ef0ee6ae25716c2b76029abfc4b1235b471d0095
[scm/test.git] / test / test-checkout.sh
1 #!/usr/bin/env bash
2
3 . "test/testlib.sh"
4
5 begin_test "checkout"
6 (
7   set -e
8
9   reponame="$(basename "$0" ".sh")"
10   setup_remote_repo "$reponame"
11
12   clone_repo "$reponame" repo
13
14   git lfs track "*.dat" 2>&1 | tee track.log
15   grep "Tracking \"\*.dat\"" track.log
16
17   contents="something something"
18   contentsize=19
19   contents_oid=$(calc_oid "$contents")
20
21   # Same content everywhere is ok, just one object in lfs db
22   printf "$contents" > file1.dat
23   printf "$contents" > file2.dat
24   printf "$contents" > file3.dat
25   mkdir folder1 folder2
26   printf "$contents" > folder1/nested.dat
27   printf "$contents" > folder2/nested.dat
28   git add file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat
29   git add .gitattributes
30   git commit -m "add files"
31
32   [ "$contents" = "$(cat file1.dat)" ]
33   [ "$contents" = "$(cat file2.dat)" ]
34   [ "$contents" = "$(cat file3.dat)" ]
35   [ "$contents" = "$(cat folder1/nested.dat)" ]
36   [ "$contents" = "$(cat folder2/nested.dat)" ]
37
38   assert_pointer "master" "file1.dat" "$contents_oid" $contentsize
39
40   # Remove the working directory
41   rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat
42
43   echo "checkout should replace all"
44   git lfs checkout
45   [ "$contents" = "$(cat file1.dat)" ]
46   [ "$contents" = "$(cat file2.dat)" ]
47   [ "$contents" = "$(cat file3.dat)" ]
48   [ "$contents" = "$(cat folder1/nested.dat)" ]
49   [ "$contents" = "$(cat folder2/nested.dat)" ]
50
51   # Remove the working directory
52   rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat
53
54   echo "checkout with filters"
55   git lfs checkout file2.dat
56   [ "$contents" = "$(cat file2.dat)" ]
57   [ ! -f file1.dat ]
58   [ ! -f file3.dat ]
59   [ ! -f folder1/nested.dat ]
60   [ ! -f folder2/nested.dat ]
61
62   echo "quotes to avoid shell globbing"
63   git lfs checkout "file*.dat"
64   [ "$contents" = "$(cat file1.dat)" ]
65   [ "$contents" = "$(cat file3.dat)" ]
66   [ ! -f folder1/nested.dat ]
67   [ ! -f folder2/nested.dat ]
68
69   echo "test subdir context"
70   pushd folder1
71   git lfs checkout nested.dat
72   [ "$contents" = "$(cat nested.dat)" ]
73   [ ! -f ../folder2/nested.dat ]
74   # test '.' in current dir
75   rm nested.dat
76   git lfs checkout .
77   [ "$contents" = "$(cat nested.dat)" ]
78   popd
79
80   echo "test folder param"
81   git lfs checkout folder2
82   [ "$contents" = "$(cat folder2/nested.dat)" ]
83
84   echo "test '.' in current dir"
85   rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat
86   git lfs checkout .
87   [ "$contents" = "$(cat file1.dat)" ]
88   [ "$contents" = "$(cat file2.dat)" ]
89   [ "$contents" = "$(cat file3.dat)" ]
90   [ "$contents" = "$(cat folder1/nested.dat)" ]
91   [ "$contents" = "$(cat folder2/nested.dat)" ]
92
93   echo "test checkout with missing data doesn't fail"
94   git push origin master
95   rm -rf .git/lfs/objects
96   rm file*.dat
97   git lfs checkout
98   [ "$(pointer $contents_oid $contentsize)" = "$(cat file1.dat)" ]
99   [ "$(pointer $contents_oid $contentsize)" = "$(cat file2.dat)" ]
100   [ "$(pointer $contents_oid $contentsize)" = "$(cat file3.dat)" ]
101   [ "$contents" = "$(cat folder1/nested.dat)" ]
102   [ "$contents" = "$(cat folder2/nested.dat)" ]
103 )
104 end_test
105
106 begin_test "checkout: without clean filter"
107 (
108   set -e
109
110   reponame="$(basename "$0" ".sh")"
111   git lfs uninstall
112
113   git clone "$GITSERVER/$reponame" checkout-without-clean
114   cd checkout-without-clean
115
116   echo "checkout without clean filter"
117   git lfs uninstall
118   git config --list > config.txt
119   grep "filter.lfs.clean" config.txt && {
120     echo "clean filter still configured:"
121     cat config.txt
122     exit 1
123   }
124   ls -al
125
126   git lfs checkout | tee checkout.txt
127   grep "Git LFS is not installed" checkout.txt
128   if [ "0" -ne "${PIPESTATUS[0]}" ]; then
129     echo >&2 "fatal: expected checkout to succeed ..."
130     exit 1
131   fi
132
133   contentsize=19
134   contents_oid=$(calc_oid "something something")
135   [ "$(pointer $contents_oid $contentsize)" = "$(cat file1.dat)" ]
136   [ "$(pointer $contents_oid $contentsize)" = "$(cat file2.dat)" ]
137   [ "$(pointer $contents_oid $contentsize)" = "$(cat file3.dat)" ]
138   [ "$(pointer $contents_oid $contentsize)" = "$(cat folder1/nested.dat)" ]
139   [ "$(pointer $contents_oid $contentsize)" = "$(cat folder2/nested.dat)" ]
140 )
141 end_test
142
143 begin_test "checkout: outside git repository"
144 (
145   set +e
146   git lfs checkout 2>&1 > checkout.log
147   res=$?
148
149   set -e
150   if [ "$res" = "0" ]; then
151     echo "Passes because $GIT_LFS_TEST_DIR is unset."
152     exit 0
153   fi
154   [ "$res" = "128" ]
155   grep "Not in a git repository" checkout.log
156 )
157 end_test