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

     1  #!/usr/bin/env bash
     2  
     3  . "$(dirname "$0")/testlib.sh"
     4  
     5  begin_test "checkout"
     6  (
     7    set -e
     8  
     9    reponame="$(basename "$0" ".sh")"
    10    setup_remote_repo "$reponame"
    11  
    12    clone_repo "$reponame" repo
    13  
    14    git lfs track "*.dat" 2>&1 | tee track.log
    15    grep "Tracking \"\*.dat\"" track.log
    16  
    17    contents="something something"
    18    contentsize=19
    19    contents_oid=$(calc_oid "$contents")
    20  
    21    # Same content everywhere is ok, just one object in lfs db
    22    printf "$contents" > file1.dat
    23    printf "$contents" > file2.dat
    24    printf "$contents" > file3.dat
    25    mkdir folder1 folder2
    26    printf "$contents" > folder1/nested.dat
    27    printf "$contents" > folder2/nested.dat
    28    git add file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat
    29    git add .gitattributes
    30    git commit -m "add files"
    31  
    32    [ "$contents" = "$(cat file1.dat)" ]
    33    [ "$contents" = "$(cat file2.dat)" ]
    34    [ "$contents" = "$(cat file3.dat)" ]
    35    [ "$contents" = "$(cat folder1/nested.dat)" ]
    36    [ "$contents" = "$(cat folder2/nested.dat)" ]
    37  
    38    assert_pointer "master" "file1.dat" "$contents_oid" $contentsize
    39  
    40    # Remove the working directory
    41    rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat
    42  
    43    echo "checkout should replace all"
    44    git lfs checkout 2>&1 | tee checkout.log
    45    [ "$contents" = "$(cat file1.dat)" ]
    46    [ "$contents" = "$(cat file2.dat)" ]
    47    [ "$contents" = "$(cat file3.dat)" ]
    48    [ "$contents" = "$(cat folder1/nested.dat)" ]
    49    [ "$contents" = "$(cat folder2/nested.dat)" ]
    50    grep "Checking out LFS objects: 100% (5/5), 95 B" checkout.log
    51  
    52    # Remove the working directory
    53    rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat
    54  
    55    echo "checkout with filters"
    56    git lfs checkout file2.dat
    57    [ "$contents" = "$(cat file2.dat)" ]
    58    [ ! -f file1.dat ]
    59    [ ! -f file3.dat ]
    60    [ ! -f folder1/nested.dat ]
    61    [ ! -f folder2/nested.dat ]
    62  
    63    echo "quotes to avoid shell globbing"
    64    git lfs checkout "file*.dat"
    65    [ "$contents" = "$(cat file1.dat)" ]
    66    [ "$contents" = "$(cat file3.dat)" ]
    67    [ ! -f folder1/nested.dat ]
    68    [ ! -f folder2/nested.dat ]
    69  
    70    echo "test subdir context"
    71    pushd folder1
    72    git lfs checkout nested.dat
    73    [ "$contents" = "$(cat nested.dat)" ]
    74    [ ! -f ../folder2/nested.dat ]
    75    # test '.' in current dir
    76    rm nested.dat
    77    git lfs checkout . 2>&1 | tee checkout.log
    78    [ "$contents" = "$(cat nested.dat)" ]
    79    popd
    80  
    81    echo "test folder param"
    82    git lfs checkout folder2
    83    [ "$contents" = "$(cat folder2/nested.dat)" ]
    84  
    85    echo "test '.' in current dir"
    86    rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat
    87    git lfs checkout .
    88    [ "$contents" = "$(cat file1.dat)" ]
    89    [ "$contents" = "$(cat file2.dat)" ]
    90    [ "$contents" = "$(cat file3.dat)" ]
    91    [ "$contents" = "$(cat folder1/nested.dat)" ]
    92    [ "$contents" = "$(cat folder2/nested.dat)" ]
    93  
    94    echo "test checkout with missing data doesn't fail"
    95    git push origin master
    96    rm -rf .git/lfs/objects
    97    rm file*.dat
    98    git lfs checkout
    99    [ "$(pointer $contents_oid $contentsize)" = "$(cat file1.dat)" ]
   100    [ "$(pointer $contents_oid $contentsize)" = "$(cat file2.dat)" ]
   101    [ "$(pointer $contents_oid $contentsize)" = "$(cat file3.dat)" ]
   102    [ "$contents" = "$(cat folder1/nested.dat)" ]
   103    [ "$contents" = "$(cat folder2/nested.dat)" ]
   104  )
   105  end_test
   106  
   107  begin_test "checkout: without clean filter"
   108  (
   109    set -e
   110  
   111    reponame="$(basename "$0" ".sh")"
   112    git lfs uninstall
   113  
   114    git clone "$GITSERVER/$reponame" checkout-without-clean
   115    cd checkout-without-clean
   116  
   117    echo "checkout without clean filter"
   118    git lfs uninstall
   119    git config --list > config.txt
   120    grep "filter.lfs.clean" config.txt && {
   121      echo "clean filter still configured:"
   122      cat config.txt
   123      exit 1
   124    }
   125    ls -al
   126  
   127    git lfs checkout | tee checkout.txt
   128    grep "Git LFS is not installed" checkout.txt
   129    if [ "0" -ne "${PIPESTATUS[0]}" ]; then
   130      echo >&2 "fatal: expected checkout to succeed ..."
   131      exit 1
   132    fi
   133  
   134    contentsize=19
   135    contents_oid=$(calc_oid "something something")
   136    [ "$(pointer $contents_oid $contentsize)" = "$(cat file1.dat)" ]
   137    [ "$(pointer $contents_oid $contentsize)" = "$(cat file2.dat)" ]
   138    [ "$(pointer $contents_oid $contentsize)" = "$(cat file3.dat)" ]
   139    [ "$(pointer $contents_oid $contentsize)" = "$(cat folder1/nested.dat)" ]
   140    [ "$(pointer $contents_oid $contentsize)" = "$(cat folder2/nested.dat)" ]
   141  )
   142  end_test
   143  
   144  begin_test "checkout: outside git repository"
   145  (
   146    set +e
   147    git lfs checkout 2>&1 > checkout.log
   148    res=$?
   149  
   150    set -e
   151    if [ "$res" = "0" ]; then
   152      echo "Passes because $GIT_LFS_TEST_DIR is unset."
   153      exit 0
   154    fi
   155    [ "$res" = "128" ]
   156    grep "Not in a git repository" checkout.log
   157  )
   158  end_test
   159  
   160  begin_test "checkout: write-only file"
   161  (
   162    set -e
   163  
   164    reponame="checkout-locked"
   165    filename="a.txt"
   166  
   167    setup_remote_repo_with_file "$reponame" "$filename"
   168  
   169    pushd "$TRASHDIR" > /dev/null
   170      GIT_LFS_SKIP_SMUDGE=1 clone_repo "$reponame" "${reponame}_checkout"
   171  
   172      chmod -w "$filename"
   173  
   174      refute_file_writeable "$filename"
   175      assert_pointer "refs/heads/master" "$filename" "$(calc_oid "$filename\n")" 6
   176  
   177      git lfs fetch
   178      git lfs checkout "$filename"
   179  
   180      refute_file_writeable "$filename"
   181      [ "$filename" = "$(cat "$filename")" ]
   182    popd > /dev/null
   183  )
   184  end_test