Imported Upstream version 2.5.1
[scm/test.git] / t / t-post-merge.sh
1 #!/usr/bin/env bash
2
3 . "$(dirname "$0")/testlib.sh"
4
5 begin_test "post-merge"
6 (
7   set -e
8
9   reponame="$(basename "$0" ".sh")"
10   setup_remote_repo "$reponame"
11
12   clone_repo "$reponame" "$reponame"
13
14   git lfs track --lockable "*.dat"
15   git lfs track "*.big" # not lockable
16   git add .gitattributes
17   git commit -m "add git attributes"
18
19
20   echo "[
21   {
22     \"CommitDate\":\"$(get_date -10d)\",
23     \"Files\":[
24       {\"Filename\":\"file1.dat\",\"Data\":\"file 1 creation\"},
25       {\"Filename\":\"file2.dat\",\"Data\":\"file 2 creation\"}]
26   },
27   {
28     \"CommitDate\":\"$(get_date -7d)\",
29     \"Files\":[
30       {\"Filename\":\"file1.dat\",\"Data\":\"file 1 updated commit 2\"},
31       {\"Filename\":\"file3.big\",\"Data\":\"file 3 creation\"},
32       {\"Filename\":\"file4.big\",\"Data\":\"file 4 creation\"}],
33     \"Tags\":[\"atag\"]
34   },
35   {
36     \"CommitDate\":\"$(get_date -5d)\",
37     \"Files\":[
38       {\"Filename\":\"file2.dat\",\"Data\":\"file 2 updated commit 3\"}]
39   },
40   {
41     \"CommitDate\":\"$(get_date -3d)\",
42     \"NewBranch\":\"branch2\",
43     \"Files\":[
44       {\"Filename\":\"file5.dat\",\"Data\":\"file 5 creation in branch2\"},
45       {\"Filename\":\"file6.big\",\"Data\":\"file 6 creation in branch2\"}]
46   },
47   {
48     \"CommitDate\":\"$(get_date -1d)\",
49     \"Files\":[
50       {\"Filename\":\"file2.dat\",\"Data\":\"file 2 updated in branch2\"},
51       {\"Filename\":\"file3.big\",\"Data\":\"file 3 updated in branch2\"}]
52   }
53   ]" | GIT_LFS_SET_LOCKABLE_READONLY=0 lfstest-testutils addcommits
54
55   # skipped setting read-only above to make bulk load simpler (no read-only issues)
56
57   git push -u origin master branch2
58
59   # re-clone the repo so we start fresh
60   cd ..
61   rm -rf "$reponame"
62   clone_repo "$reponame" "$reponame"
63
64   # this will be master
65
66   [ "$(cat file1.dat)" == "file 1 updated commit 2" ]
67   [ "$(cat file2.dat)" == "file 2 updated commit 3" ]
68   [ "$(cat file3.big)" == "file 3 creation" ]
69   [ "$(cat file4.big)" == "file 4 creation" ]
70   [ ! -e file5.dat ]
71   [ ! -e file6.big ]
72   # without the post-checkout hook, any changed files would now be writeable
73   refute_file_writeable file1.dat
74   refute_file_writeable file2.dat
75   assert_file_writeable file3.big
76   assert_file_writeable file4.big
77
78   # merge branch, with readonly option disabled to demonstrate what would happen
79   GIT_LFS_SET_LOCKABLE_READONLY=0 git merge origin/branch2
80   # branch2 had hanges to file2.dat and file5.dat which were lockable
81   # but because we disabled the readonly feature they will be writeable now
82   assert_file_writeable file2.dat
83   assert_file_writeable file5.dat
84
85   # now let's do it again with the readonly option enabled
86   git reset --hard HEAD^
87   git merge origin/branch2
88
89   # This time they should be read-only
90   refute_file_writeable file2.dat
91   refute_file_writeable file5.dat
92
93   # Confirm that contents of existing files were updated even though were read-only
94   [ "$(cat file2.dat)" == "file 2 updated in branch2" ]
95   [ "$(cat file5.dat)" == "file 5 creation in branch2" ]
96 )
97 end_test