3 . "$(dirname "$0")/testlib.sh"
5 begin_test "list a single lock with bad ref"
9 reponame="locks-list-other-branch-required"
10 setup_remote_repo "$reponame"
11 clone_repo "$reponame" "$reponame"
15 git add .gitattributes f.dat
16 git commit -m "add f.dat"
17 git push origin master:other
20 git lfs lock --json "f.dat" | tee lock.log
23 git lfs locks --path "f.dat" 2>&1 | tee locks.log
24 if [ "0" -eq "${PIPESTATUS[0]}" ]; then
25 echo >&2 "fatal: expected 'git lfs lock \'a.dat\'' to fail"
29 grep 'Expected ref "refs/heads/other", got "refs/heads/master"' locks.log
33 begin_test "list a single lock"
37 reponame="locks-list-master-branch-required"
38 setup_remote_repo_with_file "$reponame" "f.dat"
39 clone_repo "$reponame" "$reponame"
41 git lfs lock --json "f.dat" | tee lock.log
43 id=$(assert_lock lock.log f.dat)
44 assert_server_lock "$reponame" "$id" "refs/heads/master"
46 git lfs locks --path "f.dat" | tee locks.log
47 [ $(wc -l < locks.log) -eq 1 ]
48 grep "f.dat" locks.log
49 grep "Git LFS Tests" locks.log
53 begin_test "list a single lock (--json)"
57 reponame="locks_list_single_json"
58 setup_remote_repo_with_file "$reponame" "f_json.dat"
60 git lfs lock --json "f_json.dat" | tee lock.log
62 id=$(assert_lock lock.log f_json.dat)
63 assert_server_lock "$reponame" "$id"
65 git lfs locks --json --path "f_json.dat" | tee locks.log
66 grep "\"path\":\"f_json.dat\"" locks.log
67 grep "\"owner\":{\"name\":\"Git LFS Tests\"}" locks.log
71 begin_test "list locks with a limit"
75 reponame="locks_list_limit"
76 setup_remote_repo "$reponame"
77 clone_repo "$reponame" "clone_$reponame"
80 echo "foo" > "g_1.dat"
81 echo "bar" > "g_2.dat"
83 git add "g_1.dat" "g_2.dat" ".gitattributes"
84 git commit -m "add files" | tee commit.log
85 grep "3 files changed" commit.log
86 grep "create mode 100644 g_1.dat" commit.log
87 grep "create mode 100644 g_2.dat" commit.log
88 grep "create mode 100644 .gitattributes" commit.log
91 git push origin master 2>&1 | tee push.log
92 grep "master -> master" push.log
94 git lfs lock --json "g_1.dat" | tee lock.log
95 assert_server_lock "$reponame" "$(assert_log "lock.log" g_1.dat)"
97 git lfs lock --json "g_2.dat" | tee lock.log
98 assert_server_lock "$reponame" "$(assert_lock "lock.log" g_2.dat)"
100 git lfs locks --limit 1 | tee locks.log
101 [ $(wc -l < locks.log) -eq 1 ]
105 begin_test "list locks with pagination"
109 reponame="locks_list_paginate"
110 setup_remote_repo "$reponame"
111 clone_repo "$reponame" "clone_$reponame"
113 git lfs track "*.dat"
114 for i in $(seq 1 5); do
115 echo "$i" > "h_$i.dat"
118 git add "h_1.dat" "h_2.dat" "h_3.dat" "h_4.dat" "h_5.dat" ".gitattributes"
120 git commit -m "add files" | tee commit.log
121 grep "6 files changed" commit.log
122 for i in $(seq 1 5); do
123 grep "create mode 100644 h_$i.dat" commit.log
125 grep "create mode 100644 .gitattributes" commit.log
127 git push origin master 2>&1 | tee push.log
128 grep "master -> master" push.log
130 for i in $(seq 1 5); do
131 git lfs lock --json "h_$i.dat" | tee lock.log
132 assert_server_lock "$reponame" "$(assert_lock "lock.log" "h_$1.dat")"
135 # The server will return, at most, three locks at a time
136 git lfs locks --limit 4 | tee locks.log
137 [ $(wc -l < locks.log) -eq 4 ]
141 begin_test "cached locks"
145 reponame="cached_locks"
146 setup_remote_repo "remote_$reponame"
147 clone_repo "remote_$reponame" "clone_$reponame"
149 git lfs track "*.dat"
150 echo "foo" > "cached1.dat"
151 echo "bar" > "cached2.dat"
153 git add "cached1.dat" "cached2.dat" ".gitattributes"
154 git commit -m "add files" | tee commit.log
155 grep "3 files changed" commit.log
156 grep "create mode 100644 cached1.dat" commit.log
157 grep "create mode 100644 cached2.dat" commit.log
158 grep "create mode 100644 .gitattributes" commit.log
160 git push origin master 2>&1 | tee push.log
161 grep "master -> master" push.log
163 git lfs lock --json "cached1.dat" | tee lock.log
164 assert_server_lock "$(assert_lock "lock.log" cached1.dat)"
166 git lfs lock --json "cached2.dat" | tee lock.log
167 assert_server_lock "$(assert_lock "lock.log" cached2.dat)"
169 git lfs locks --local | tee locks.log
170 [ $(wc -l < locks.log) -eq 2 ]
172 # delete the remote to prove we're using the local records
173 git remote remove origin
175 git lfs locks --local --path "cached1.dat" | tee locks.log
176 [ $(wc -l < locks.log) -eq 1 ]
177 grep "cached1.dat" locks.log
179 git lfs locks --local --limit 1 | tee locks.log
180 [ $(wc -l < locks.log) -eq 1 ]