File: t-post-merge.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 (97 lines) | stat: -rwxr-xr-x 2,991 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash

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

begin_test "post-merge"
(
  set -e

  reponame="$(basename "$0" ".sh")"
  setup_remote_repo "$reponame"

  clone_repo "$reponame" "$reponame"

  git lfs track --lockable "*.dat"
  git lfs track "*.big" # not lockable
  git add .gitattributes
  git commit -m "add git attributes"


  echo "[
  {
    \"CommitDate\":\"$(get_date -10d)\",
    \"Files\":[
      {\"Filename\":\"file1.dat\",\"Data\":\"file 1 creation\"},
      {\"Filename\":\"file2.dat\",\"Data\":\"file 2 creation\"}]
  },
  {
    \"CommitDate\":\"$(get_date -7d)\",
    \"Files\":[
      {\"Filename\":\"file1.dat\",\"Data\":\"file 1 updated commit 2\"},
      {\"Filename\":\"file3.big\",\"Data\":\"file 3 creation\"},
      {\"Filename\":\"file4.big\",\"Data\":\"file 4 creation\"}],
    \"Tags\":[\"atag\"]
  },
  {
    \"CommitDate\":\"$(get_date -5d)\",
    \"Files\":[
      {\"Filename\":\"file2.dat\",\"Data\":\"file 2 updated commit 3\"}]
  },
  {
    \"CommitDate\":\"$(get_date -3d)\",
    \"NewBranch\":\"branch2\",
    \"Files\":[
      {\"Filename\":\"file5.dat\",\"Data\":\"file 5 creation in branch2\"},
      {\"Filename\":\"file6.big\",\"Data\":\"file 6 creation in branch2\"}]
  },
  {
    \"CommitDate\":\"$(get_date -1d)\",
    \"Files\":[
      {\"Filename\":\"file2.dat\",\"Data\":\"file 2 updated in branch2\"},
      {\"Filename\":\"file3.big\",\"Data\":\"file 3 updated in branch2\"}]
  }
  ]" | GIT_LFS_SET_LOCKABLE_READONLY=0 lfstest-testutils addcommits

  # skipped setting read-only above to make bulk load simpler (no read-only issues)

  git push -u origin main branch2

  # re-clone the repo so we start fresh
  cd ..
  rm -rf "$reponame"
  clone_repo "$reponame" "$reponame"

  # this will be main

  [ "$(cat file1.dat)" == "file 1 updated commit 2" ]
  [ "$(cat file2.dat)" == "file 2 updated commit 3" ]
  [ "$(cat file3.big)" == "file 3 creation" ]
  [ "$(cat file4.big)" == "file 4 creation" ]
  [ ! -e file5.dat ]
  [ ! -e file6.big ]
  # without the post-checkout hook, any changed files would now be writeable
  refute_file_writeable file1.dat
  refute_file_writeable file2.dat
  assert_file_writeable file3.big
  assert_file_writeable file4.big

  # merge branch, with readonly option disabled to demonstrate what would happen
  GIT_LFS_SET_LOCKABLE_READONLY=0 git merge origin/branch2
  # branch2 had hanges to file2.dat and file5.dat which were lockable
  # but because we disabled the readonly feature they will be writeable now
  assert_file_writeable file2.dat
  assert_file_writeable file5.dat

  # now let's do it again with the readonly option enabled
  git reset --hard HEAD^
  git merge origin/branch2

  # This time they should be read-only
  refute_file_writeable file2.dat
  refute_file_writeable file5.dat

  # Confirm that contents of existing files were updated even though were read-only
  [ "$(cat file2.dat)" == "file 2 updated in branch2" ]
  [ "$(cat file5.dat)" == "file 5 creation in branch2" ]
)
end_test