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

     1  #!/usr/bin/env bash
     2  
     3  . "$(dirname "$0")/testlib.sh"
     4  
     5  # HACK(taylor): git uses ".g<hash>" in the version name to signal that it is
     6  # from the "next" branch, which is the only (current) version of Git that has
     7  # support for the filter protocol.
     8  #
     9  ensure_git_version_isnt $VERSION_LOWER "2.11.0"
    10  
    11  begin_test "filter process: checking out a branch"
    12  (
    13    set -e
    14  
    15    reponame="filter_process_checkout"
    16    setup_remote_repo "$reponame"
    17    clone_repo "$reponame" repo
    18  
    19    git lfs track "*.dat"
    20    git add .gitattributes
    21    git commit -m "initial commit"
    22  
    23    contents_a="contents_a"
    24    contents_a_oid="$(calc_oid $contents_a)"
    25    printf "$contents_a" > a.dat
    26  
    27    git add a.dat
    28    git commit -m "add a.dat"
    29  
    30    git checkout -b b
    31  
    32    contents_b="contents_b"
    33    contents_b_oid="$(calc_oid $contents_b)"
    34    printf "$contents_b" > b.dat
    35  
    36    git add b.dat
    37    git commit -m "add b.dat"
    38  
    39    git push origin --all
    40  
    41    pushd ..
    42      # Git will choose filter.lfs.process over `filter.lfs.clean` and
    43      # `filter.lfs.smudge`
    44      GIT_TRACE_PACKET=1 git \
    45        -c "filter.lfs.process=git-lfs filter-process" \
    46        -c "filter.lfs.clean=false"\
    47        -c "filter.lfs.smudge=false" \
    48        -c "filter.lfs.required=true" \
    49        clone "$GITSERVER/$reponame" "$reponame-assert"
    50  
    51      cd "$reponame-assert"
    52  
    53      # Assert that we are on the "master" branch, and have a.dat
    54      [ "master" = "$(git rev-parse --abbrev-ref HEAD)" ]
    55      [ "$contents_a" = "$(cat a.dat)" ]
    56      assert_pointer "master" "a.dat" "$contents_a_oid" 10
    57  
    58      git checkout b
    59  
    60      # Assert that we are on the "b" branch, and have b.dat
    61      [ "b" = "$(git rev-parse --abbrev-ref HEAD)" ]
    62      [ "$contents_b" = "$(cat b.dat)" ]
    63      assert_pointer "b" "b.dat" "$contents_b_oid" 10
    64    popd
    65  )
    66  end_test
    67  
    68  begin_test "filter process: adding a file"
    69  (
    70    set -e
    71  
    72    reponame="filter_process_add"
    73    setup_remote_repo "$reponame"
    74    clone_repo "$reponame" "$reponame"
    75  
    76    git lfs track "*.dat"
    77    git add .gitattributes
    78    git commit -m "initial commit"
    79  
    80    contents="contents"
    81    contents_oid="$(calc_oid "$contents")"
    82    printf "$contents" > a.dat
    83  
    84    git add a.dat
    85  
    86    expected="$(pointer "$contents_oid" "${#contents}")"
    87    got="$(git cat-file -p :a.dat)"
    88  
    89    diff -u <(echo "$expected") <(echo "$got")
    90  )
    91  end_test
    92  
    93  # https://github.com/git-lfs/git-lfs/issues/1697
    94  begin_test "filter process: add a file with 1024 bytes"
    95  (
    96    set -e
    97  
    98    mkdir repo-issue-1697
    99    cd repo-issue-1697
   100    git init
   101    git lfs track "*.dat"
   102    dd if=/dev/zero of=first.dat bs=1024 count=1
   103    printf "any contents" > second.dat
   104    git add .
   105  )
   106  end_test
   107  
   108  
   109