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

     1  #!/usr/bin/env bash
     2  
     3  . "$(dirname "$0")/testlib.sh"
     4  
     5  begin_test "multiple revs with same OID get pushed once"
     6  (
     7    set -e
     8  
     9    reponame="mutliple-revs-one-oid"
    10    setup_remote_repo "$reponame"
    11    clone_repo "$reponame" "$reponame"
    12  
    13    git lfs track "*.dat"
    14    git add .gitattributes
    15    git commit -m "initial commit"
    16  
    17    contents="contents"
    18    contents_oid="$(calc_oid "$contents")"
    19  
    20    # Stash the contents of the file that we want to commit in .git/lfs/objects.
    21    object_dir="$(echo $contents_oid \
    22      | awk '{ print substr($0, 0, 2) "/" substr($0, 3, 2) }')"
    23    mkdir -p ".git/lfs/objects/$object_dir"
    24    printf "$contents" > ".git/lfs/objects/$object_dir/$contents_oid"
    25  
    26    # Create a pointer with the old "http://git-media.io" spec
    27    legacy_pointer="$(pointer $contents_oid 8 http://git-media.io/v/2)"
    28    # Create a pointer with the latest spec to create a modification, but leave
    29    # the OID untouched.
    30    latest_pointer="$(pointer $contents_oid 8)"
    31  
    32    # Commit the legacy pointer
    33    printf "$legacy_pointer" > a.dat
    34    git add a.dat
    35    git commit -m "commit legacy"
    36  
    37    # Commit the new pointer, causing a diff on a.dat, but leaving the OID
    38    # unchanged.
    39    printf "$latest_pointer" > a.dat
    40    git add a.dat
    41    git commit -m "commit latest"
    42  
    43    # Delay the push until here, so the server doesn't have a copy of the OID that
    44    # we're trying to push.
    45    git push origin master 2>&1 | tee push.log
    46    grep "Uploading LFS objects: 100% (1/1), 8 B" push.log
    47  
    48    assert_server_object "$reponame" "$contents_oid"
    49  )
    50  end_test