github.com/git-lfs/git-lfs@v2.5.2+incompatible/t/t-install.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  . "$(dirname "$0")/testlib.sh"
     4  
     5  begin_test "install again"
     6  (
     7    set -eo pipefail
     8  
     9    smudge="$(git config filter.lfs.smudge)"
    10    clean="$(git config filter.lfs.clean)"
    11    filter="$(git config filter.lfs.process)"
    12  
    13    [ "$smudge" = "git-lfs smudge -- %f" ]
    14    [ "$clean" = "git-lfs clean -- %f" ]
    15    [ "$filter" = "git-lfs filter-process" ]
    16  
    17    GIT_TRACE=1 git lfs install --skip-repo 2>&1 | tee install.log
    18  
    19    if grep -q "--replace-all" install.log; then
    20      echo >&2 "fatal: unexpected git config --replace-all via 'git lfs install'"
    21      exit 1
    22    fi
    23  
    24    [ "$smudge" = "$(git config filter.lfs.smudge)" ]
    25    [ "$clean" = "$(git config filter.lfs.clean)" ]
    26    [ "$filter" = "$(git config filter.lfs.process)" ]
    27  )
    28  end_test
    29  
    30  begin_test "install with old (non-upgradeable) settings"
    31  (
    32    set -e
    33  
    34    git config --global filter.lfs.smudge "git-lfs smudge --something %f"
    35    git config --global filter.lfs.clean "git-lfs clean --something %f"
    36  
    37    git lfs install | tee install.log
    38    [ "${PIPESTATUS[0]}" = 0 ]
    39  
    40    grep -E "(clean|smudge)\" attribute should be" install.log
    41    [ `grep -c "(MISSING)" install.log` = "0" ]
    42  
    43    [ "git-lfs smudge --something %f" = "$(git config --global filter.lfs.smudge)" ]
    44    [ "git-lfs clean --something %f" = "$(git config --global filter.lfs.clean)" ]
    45  
    46    git lfs install --force
    47    [ "git-lfs smudge -- %f" = "$(git config --global filter.lfs.smudge)" ]
    48    [ "git-lfs clean -- %f" = "$(git config --global filter.lfs.clean)" ]
    49  )
    50  end_test
    51  
    52  begin_test "install with upgradeable settings"
    53  (
    54    set -e
    55  
    56    git config --global filter.lfs.smudge "git-lfs smudge %f"
    57    git config --global filter.lfs.clean "git-lfs clean %f"
    58  
    59    # should not need force, should upgrade this old style
    60    git lfs install
    61    [ "git-lfs smudge -- %f" = "$(git config --global filter.lfs.smudge)" ]
    62    [ "git-lfs clean -- %f" = "$(git config --global filter.lfs.clean)" ]
    63    [ "git-lfs filter-process" = "$(git config --global filter.lfs.process)" ]
    64  )
    65  end_test
    66  
    67  begin_test "install updates repo hooks"
    68  (
    69    set -e
    70  
    71    mkdir install-repo-hooks
    72    cd install-repo-hooks
    73    git init
    74  
    75    pre_push_hook="#!/bin/sh
    76  command -v git-lfs >/dev/null 2>&1 || { echo >&2 \"\\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.\\n\"; exit 2; }
    77  git lfs pre-push \"\$@\""
    78  
    79    post_checkout_hook="#!/bin/sh
    80  command -v git-lfs >/dev/null 2>&1 || { echo >&2 \"\\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-checkout.\\n\"; exit 2; }
    81  git lfs post-checkout \"\$@\""
    82  
    83    post_commit_hook="#!/bin/sh
    84  command -v git-lfs >/dev/null 2>&1 || { echo >&2 \"\\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-commit.\\n\"; exit 2; }
    85  git lfs post-commit \"\$@\""
    86  
    87    post_merge_hook="#!/bin/sh
    88  command -v git-lfs >/dev/null 2>&1 || { echo >&2 \"\\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-merge.\\n\"; exit 2; }
    89  git lfs post-merge \"\$@\""
    90  
    91    [ "Updated git hooks.
    92  Git LFS initialized." = "$(git lfs install)" ]
    93    [ "$pre_push_hook" = "$(cat .git/hooks/pre-push)" ]
    94    [ "$post_checkout_hook" = "$(cat .git/hooks/post-checkout)" ]
    95    [ "$post_commit_hook" = "$(cat .git/hooks/post-commit)" ]
    96    [ "$post_merge_hook" = "$(cat .git/hooks/post-merge)" ]
    97  
    98    # replace old hook
    99    # more-comprehensive hook update tests are in test-update.sh
   100    echo "#!/bin/sh
   101  git lfs push --stdin \$*" > .git/hooks/pre-push
   102    [ "Updated git hooks.
   103  Git LFS initialized." = "$(git lfs install)" ]
   104    [ "$pre_push_hook" = "$(cat .git/hooks/pre-push)" ]
   105  
   106    # don't replace unexpected hook
   107    expected="Hook already exists: pre-push
   108  
   109  	test
   110  
   111  To resolve this, either:
   112    1: run \`git lfs update --manual\` for instructions on how to merge hooks.
   113    2: run \`git lfs update --force\` to overwrite your hook."
   114  
   115    echo "test" > .git/hooks/pre-push
   116    echo "test" > .git/hooks/post-checkout
   117    echo "test" > .git/hooks/post-commit
   118    echo "test" > .git/hooks/post-merge
   119    [ "test" = "$(cat .git/hooks/pre-push)" ]
   120    [ "$expected" = "$(git lfs install 2>&1)" ]
   121    [ "test" = "$(cat .git/hooks/pre-push)" ]
   122    [ "test" = "$(cat .git/hooks/post-checkout)" ]
   123    [ "test" = "$(cat .git/hooks/post-commit)" ]
   124    [ "test" = "$(cat .git/hooks/post-merge)" ]
   125  
   126    # Make sure returns non-zero
   127    set +e
   128    git lfs install
   129    if [ $? -eq 0 ]
   130    then
   131      exit 1
   132    fi
   133    set -e
   134  
   135    # force replace unexpected hook
   136    [ "Updated git hooks.
   137  Git LFS initialized." = "$(git lfs install --force)" ]
   138    [ "$pre_push_hook" = "$(cat .git/hooks/pre-push)" ]
   139    [ "$post_checkout_hook" = "$(cat .git/hooks/post-checkout)" ]
   140    [ "$post_commit_hook" = "$(cat .git/hooks/post-commit)" ]
   141    [ "$post_merge_hook" = "$(cat .git/hooks/post-merge)" ]
   142  
   143    has_test_dir || exit 0
   144  
   145    echo "test with bare repository"
   146    cd ..
   147    git clone --mirror install-repo-hooks bare-install-repo-hooks
   148    cd bare-install-repo-hooks
   149    git lfs env
   150    git lfs install
   151    ls -al hooks
   152    [ "$pre_push_hook" = "$(cat hooks/pre-push)" ]
   153  )
   154  end_test
   155  
   156  begin_test "install outside repository directory"
   157  (
   158    set -e
   159    if [ -d "hooks" ]; then
   160      ls -al
   161      echo "hooks dir exists"
   162      exit 1
   163    fi
   164  
   165    git lfs install 2>&1 > check.log
   166  
   167    if [ -d "hooks" ]; then
   168      ls -al
   169      echo "hooks dir exists"
   170      exit 1
   171    fi
   172  
   173    cat check.log
   174  
   175    # doesn't print this because being in a git repo is not necessary for install
   176    [ "$(grep -c "Not in a git repository" check.log)" = "0" ]
   177  )
   178  end_test
   179  
   180  begin_test "install --skip-smudge"
   181  (
   182    set -e
   183  
   184    mkdir install-skip-smudge-test
   185    cd install-skip-smudge-test
   186  
   187    git lfs install
   188    [ "git-lfs clean -- %f" = "$(git config --global filter.lfs.clean)" ]
   189    [ "git-lfs smudge -- %f" = "$(git config --global filter.lfs.smudge)" ]
   190    [ "git-lfs filter-process" = "$(git config --global filter.lfs.process)" ]
   191  
   192    git lfs install --skip-smudge
   193    [ "git-lfs clean -- %f" = "$(git config --global filter.lfs.clean)" ]
   194    [ "git-lfs smudge --skip -- %f" = "$(git config --global filter.lfs.smudge)" ]
   195    [ "git-lfs filter-process --skip" = "$(git config --global filter.lfs.process)" ]
   196  
   197    git lfs install
   198    [ "git-lfs clean -- %f" = "$(git config --global filter.lfs.clean)" ]
   199    [ "git-lfs smudge -- %f" = "$(git config --global filter.lfs.smudge)" ]
   200    [ "git-lfs filter-process" = "$(git config --global filter.lfs.process)" ]
   201  
   202    [ ! -e "lfs" ]
   203  )
   204  end_test
   205  
   206  begin_test "install --local"
   207  (
   208    set -e
   209  
   210    # old values that should be ignored by `install --local`
   211    git config --global filter.lfs.smudge "git lfs smudge %f"
   212    git config --global filter.lfs.clean "git lfs clean %f"
   213  
   214    mkdir install-local-repo
   215    cd install-local-repo
   216    git init
   217    git lfs install --local
   218  
   219    [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
   220    [ "git-lfs clean -- %f" = "$(git config --local filter.lfs.clean)" ]
   221    [ "git lfs clean %f" = "$(git config --global filter.lfs.clean)" ]
   222    [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ]
   223    [ "git-lfs filter-process" = "$(git config --local filter.lfs.process)" ]
   224  )
   225  end_test
   226  
   227  begin_test "install --local outside repository"
   228  (
   229    # If run inside the git-lfs source dir this will update its .git/config & cause issues
   230    if [ "$GIT_LFS_TEST_DIR" == "" ]; then
   231      echo "Skipping install --local because GIT_LFS_TEST_DIR is not set"
   232      exit 0
   233    fi
   234  
   235    set +e
   236  
   237    has_test_dir || exit 0
   238  
   239    git lfs install --local 2> err.log
   240    res=$?
   241  
   242    [ "Not in a git repository." = "$(cat err.log)" ]
   243    [ "0" != "$res" ]
   244  )
   245  end_test
   246  
   247  begin_test "install in directory without access to .git/lfs"
   248  (
   249    set -e
   250    mkdir not-a-repo
   251    cd not-a-repo
   252    mkdir .git
   253    touch .git/lfs
   254    touch lfs
   255  
   256    git config --global filter.lfs.clean whatevs
   257    [ "whatevs" = "$(git config filter.lfs.clean)" ]
   258  
   259    git lfs install --force
   260  
   261    [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
   262  )
   263  end_test
   264  
   265  
   266  begin_test "install in repo without changing hooks"
   267  (
   268    set -e
   269    git init non-lfs-repo
   270    cd non-lfs-repo
   271  
   272    git lfs install --skip-repo
   273  
   274    # should not install hooks
   275    [ ! -f .git/hooks/pre-push ]
   276    [ ! -f .git/hooks/post-checkout ]
   277    [ ! -f .git/hooks/post-merge ]
   278    [ ! -f .git/hooks/post-commit ]
   279  
   280    # filters should still be installed
   281    [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
   282    [ "git-lfs smudge -- %f" = "$(git config filter.lfs.smudge)" ]
   283    [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ]
   284  )
   285  end_test
   286  
   287  
   288  begin_test "can install when multiple global values registered"
   289  (
   290    set -e
   291  
   292    git config --global filter.lfs.smudge "git-lfs smudge --something %f"
   293    git config --global --add filter.lfs.smudge "git-lfs smudge --something-else %f"
   294  
   295    git lfs install --force
   296  )
   297  end_test