File: t-duplicate-oids.sh

package info (click to toggle)
git-lfs 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,808 kB
  • sloc: sh: 21,256; makefile: 507; ruby: 417
file content (50 lines) | stat: -rwxr-xr-x 1,513 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash

. "$(dirname "$0")/testlib.sh"

begin_test "multiple revs with same OID get pushed once"
(
  set -e

  reponame="multiple-revs-one-oid"
  setup_remote_repo "$reponame"
  clone_repo "$reponame" "$reponame"

  git lfs track "*.dat"
  git add .gitattributes
  git commit -m "initial commit"

  contents="contents"
  contents_oid="$(calc_oid "$contents")"

  # Stash the contents of the file that we want to commit in .git/lfs/objects.
  object_dir="$(echo $contents_oid \
    | awk '{ print substr($0, 1, 2) "/" substr($0, 3, 2) }')"
  mkdir -p ".git/lfs/objects/$object_dir"
  printf "%s" "$contents" > ".git/lfs/objects/$object_dir/$contents_oid"

  # Create a pointer with the old "http://git-media.io" spec
  legacy_pointer="$(pointer $contents_oid 8 http://git-media.io/v/2)"
  # Create a pointer with the latest spec to create a modification, but leave
  # the OID untouched.
  latest_pointer="$(pointer $contents_oid 8)"

  # Commit the legacy pointer
  printf "%s" "$legacy_pointer" > a.dat
  git add a.dat
  git commit -m "commit legacy"

  # Commit the new pointer, causing a diff on a.dat, but leaving the OID
  # unchanged.
  printf "%s" "$latest_pointer" > a.dat
  git add a.dat
  git commit -m "commit latest"

  # Delay the push until here, so the server doesn't have a copy of the OID that
  # we're trying to push.
  git push origin main 2>&1 | tee push.log
  grep "Uploading LFS objects: 100% (1/1), 8 B" push.log

  assert_server_object "$reponame" "$contents_oid"
)
end_test