Skip to content

Commit 2aa86b3

Browse files
authored
Add test for tagging from workspaces (#542)
* Add test for tagging from workspaces * Fix base for tags
1 parent fec5fe6 commit 2aa86b3

File tree

2 files changed

+289
-4
lines changed

2 files changed

+289
-4
lines changed

src/history.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn find_unapply_base(
8888
let contained_in_commit = transaction.repo().find_commit(contained_in)?;
8989
let oid = filter::apply_to_commit(filter, &contained_in_commit, transaction)?;
9090
if oid != git2::Oid::zero() {
91-
bm.insert(contained_in, oid);
91+
bm.insert(oid, contained_in);
9292
}
9393
let mut walk = transaction.repo().revwalk()?;
9494
walk.set_sorting(git2::Sort::TOPOLOGICAL)?;
@@ -98,7 +98,7 @@ fn find_unapply_base(
9898
let original = transaction.repo().find_commit(original?)?;
9999
if filtered == filter::apply_to_commit(filter, &original, transaction)? {
100100
bm.insert(filtered, original.id());
101-
tracing::info!("found original properly",);
101+
tracing::info!("found original properly {}", original.id());
102102
return Ok(original.id());
103103
}
104104
}
@@ -229,7 +229,7 @@ fn find_oldest_similar_commit(
229229
prev_rev = rev;
230230
}
231231
tracing::info!("bottom");
232-
return Ok(unfiltered);
232+
return Ok(prev_rev);
233233
}
234234

235235
fn find_new_branch_base(
@@ -251,7 +251,7 @@ fn find_new_branch_base(
251251
let rev = rev?;
252252
if let Ok(base) = find_unapply_base(transaction, bm, filter, contained_in, rev) {
253253
if base != git2::Oid::zero() {
254-
tracing::info!("new branch base: {:?}", base);
254+
tracing::info!("new branch base: {:?} mapping to {:?}", base, rev);
255255
let base =
256256
if let Ok(new_base) = find_oldest_similar_commit(transaction, filter, base) {
257257
new_base
@@ -298,6 +298,18 @@ pub fn unapply_filter(
298298
old
299299
};
300300

301+
if new == old {
302+
tracing::info!("New == old. Pushing a new branch?");
303+
let ret = if let Some(original) = bm.get(&new) {
304+
tracing::info!("Found in bm {}", original);
305+
*original
306+
} else {
307+
tracing::info!("Had to go through the whole thing",);
308+
find_original(transaction, filterobj, original_target, new)?
309+
};
310+
return Ok(UnapplyResult::Done(ret));
311+
}
312+
301313
tracing::info!("before walk");
302314

303315
let walk = {

tests/proxy/workspace_tags.t

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
$ . ${TESTDIR}/setup_test_env.sh
2+
$ cd ${TESTTMP}
3+
4+
5+
$ git clone -q http://localhost:8001/real_repo.git
6+
warning: You appear to have cloned an empty repository.
7+
8+
$ curl -s http://localhost:8002/version
9+
Version: 0.3.0
10+
11+
$ cd real_repo
12+
13+
$ git status
14+
On branch master
15+
16+
No commits yet
17+
18+
nothing to commit (create/copy files and use "git add" to track)
19+
20+
$ git checkout -b master
21+
Switched to a new branch 'master'
22+
23+
$ mkdir ws
24+
$ cat > ws/workspace.josh <<EOF
25+
> a/b = :/sub2
26+
> c = :/sub1
27+
> EOF
28+
29+
$ git add ws
30+
$ git commit -m "add workspace" 1> /dev/null
31+
32+
$ echo content1 > file1 1> /dev/null
33+
$ git add .
34+
$ git commit -m "initial" 1> /dev/null
35+
36+
$ git checkout -b new1
37+
Switched to a new branch 'new1'
38+
$ echo content > newfile1 1> /dev/null
39+
$ git add .
40+
$ git commit -m "add newfile1" 1> /dev/null
41+
42+
$ git checkout master 1> /dev/null
43+
Switched to branch 'master'
44+
$ echo content > newfile_master 1> /dev/null
45+
$ git add .
46+
$ git commit -m "newfile master" 1> /dev/null
47+
48+
$ git merge new1 --no-ff
49+
Merge made by the 'ort' strategy.
50+
newfile1 | 0
51+
1 file changed, 0 insertions(+), 0 deletions(-)
52+
create mode 100644 newfile1
53+
54+
$ mkdir sub3
55+
$ echo contents3 > sub3/file3
56+
$ git add sub3
57+
$ git commit -m "add file3" 1> /dev/null
58+
59+
$ mkdir -p sub1/subsub
60+
$ echo contents1 > sub1/subsub/file1
61+
$ git add .
62+
$ git commit -m "add file1" 1> /dev/null
63+
64+
$ mkdir sub2
65+
$ echo contents1 > sub2/file2
66+
$ git add sub2
67+
$ git commit -m "add file2" 1> /dev/null
68+
69+
70+
$ git log --graph --pretty=%s
71+
* add file2
72+
* add file1
73+
* add file3
74+
* Merge branch 'new1'
75+
|\
76+
| * add newfile1
77+
* | newfile master
78+
|/
79+
* initial
80+
* add workspace
81+
82+
83+
$ git push
84+
To http://localhost:8001/real_repo.git
85+
* [new branch] master -> master
86+
87+
$ cd ${TESTTMP}
88+
89+
$ git clone -q http://localhost:8002/real_repo.git:workspace=ws.git ws
90+
$ cd ws
91+
$ tree
92+
.
93+
|-- a
94+
| `-- b
95+
| `-- file2
96+
|-- c
97+
| `-- subsub
98+
| `-- file1
99+
`-- workspace.josh
100+
101+
4 directories, 3 files
102+
103+
$ cat workspace.josh
104+
a/b = :/sub2
105+
c = :/sub1
106+
107+
$ git log --graph --pretty=%s
108+
* add file2
109+
* add file1
110+
* add workspace
111+
112+
$ echo newfile_1_contents > c/subsub/newfile_1
113+
$ echo newfile_2_contents > a/b/newfile_2
114+
115+
$ git add .
116+
117+
$ git commit -m "add in filter" 1> /dev/null
118+
119+
$ git push 2>&1 >/dev/null | sed -e 's/[ ]*$//g'
120+
remote: josh-proxy
121+
remote: response from upstream:
122+
remote: To http://localhost:8001/real_repo.git
123+
remote: 176e8e0..11e2559 JOSH_PUSH -> master
124+
remote: REWRITE(5fa942ed9d35f280b35df2c4ef7acd23319271a5 -> 2cbcd105ead63a4fecf486b949db7f44710300e5)
125+
remote:
126+
remote:
127+
To http://localhost:8002/real_repo.git:workspace=ws.git
128+
6be0d68..5fa942e master -> master
129+
$ git log --graph --oneline
130+
* 5fa942e add in filter
131+
* 6be0d68 add file2
132+
* 833812f add file1
133+
* 1b46698 add workspace
134+
135+
$ cd ${TESTTMP}/real_repo
136+
$ git pull 2>/dev/null 1>/dev/null
137+
$ git log --graph --oneline
138+
* 11e2559 add in filter
139+
* 176e8e0 add file2
140+
* 76cd9e6 add file1
141+
* 828956f add file3
142+
* 65ca339 Merge branch 'new1'
143+
|\
144+
| * 902bb8f add newfile1
145+
* | f5719cb newfile master
146+
|/
147+
* a75eedb initial
148+
* 8360d96 add workspace
149+
150+
# Pushing a tag from the workspace on the latest commit. It also gets rewritten, because we didn't
151+
# fetch yet.
152+
153+
$ cd ${TESTTMP}/ws
154+
$ git tag tag_from_ws_1
155+
156+
$ git push origin tag_from_ws_1 -o base=refs/heads/master
157+
remote: josh-proxy
158+
remote: response from upstream:
159+
remote: To http://localhost:8001/real_repo.git
160+
remote: * [new tag] JOSH_PUSH -> tag_from_ws_1
161+
remote: REWRITE(5fa942ed9d35f280b35df2c4ef7acd23319271a5 -> 2cbcd105ead63a4fecf486b949db7f44710300e5)
162+
remote:
163+
remote:
164+
To http://localhost:8002/real_repo.git:workspace=ws.git
165+
* [new tag] tag_from_ws_1 -> tag_from_ws_1
166+
167+
$ git fetch --all
168+
Fetching origin
169+
From http://localhost:8002/real_repo.git:workspace=ws
170+
+ 5fa942e...2cbcd10 master -> origin/master (forced update)
171+
172+
$ cd ${TESTTMP}/real_repo
173+
174+
$ git pull --tags --rebase 1> /dev/null
175+
From http://localhost:8001/real_repo
176+
* [new tag] tag_from_ws_1 -> tag_from_ws_1
177+
178+
$ git log --tags --graph --pretty="%s %d"
179+
* add in filter (HEAD -> master, tag: tag_from_ws_1, origin/master)
180+
* add file2
181+
* add file1
182+
* add file3
183+
* Merge branch 'new1'
184+
|\
185+
| * add newfile1 (new1)
186+
* | newfile master
187+
|/
188+
* initial
189+
* add workspace
190+
191+
# Pushing a tag from the workspace on an older commit
192+
193+
$ cd ${TESTTMP}/ws
194+
$ git checkout HEAD~3 2>/dev/null
195+
$ git log --oneline
196+
1b46698 add workspace
197+
$ git tag tag_from_ws_2
198+
$ git push origin tag_from_ws_2 -o base=refs/heads/master 2>&1 >/dev/null | sed -e 's/[ ]*$//g'
199+
remote: josh-proxy
200+
remote: response from upstream:
201+
remote: To http://localhost:8001/real_repo.git
202+
remote: * [new tag] JOSH_PUSH -> tag_from_ws_2
203+
remote: warnings:
204+
remote: No match for "c = :/sub1"
205+
remote: No match for "a/b = :/sub2"
206+
remote:
207+
remote:
208+
To http://localhost:8002/real_repo.git:workspace=ws.git
209+
* [new tag] tag_from_ws_2 -> tag_from_ws_2
210+
211+
$ cd ${TESTTMP}/real_repo
212+
213+
$ git pull --tags --rebase 1> /dev/null
214+
From http://localhost:8001/real_repo
215+
* [new tag] tag_from_ws_2 -> tag_from_ws_2
216+
217+
$ git log --tags --graph --pretty="%s %d"
218+
* add in filter (HEAD -> master, tag: tag_from_ws_1, origin/master)
219+
* add file2
220+
* add file1
221+
* add file3
222+
* Merge branch 'new1'
223+
|\
224+
| * add newfile1 (new1)
225+
* | newfile master
226+
|/
227+
* initial
228+
* add workspace (tag: tag_from_ws_2)
229+
230+
$ bash ${TESTDIR}/destroy_test_env.sh
231+
"real_repo.git" = [
232+
':/sub1',
233+
':/sub1/subsub',
234+
':/sub2',
235+
':/sub3',
236+
':/ws',
237+
':workspace=ws',
238+
]
239+
refs
240+
|-- heads
241+
|-- josh
242+
| |-- filtered
243+
| | `-- real_repo.git
244+
| | |-- %3A%2Fsub1
245+
| | | `-- HEAD
246+
| | |-- %3A%2Fsub1%2Fsubsub
247+
| | | `-- HEAD
248+
| | |-- %3A%2Fsub2
249+
| | | `-- HEAD
250+
| | |-- %3A%2Fsub3
251+
| | | `-- HEAD
252+
| | |-- %3A%2Fws
253+
| | | `-- HEAD
254+
| | `-- %3Aworkspace=ws
255+
| | `-- HEAD
256+
| |-- rewrites
257+
| | `-- real_repo.git
258+
| | `-- 7bd92d97e96693ea7fd7eb5757b3580002889948
259+
| | `-- r_2cbcd105ead63a4fecf486b949db7f44710300e5
260+
| `-- upstream
261+
| `-- real_repo.git
262+
| |-- HEAD
263+
| `-- refs
264+
| |-- heads
265+
| | `-- master
266+
| `-- tags
267+
| `-- tag_from_ws_1
268+
|-- namespaces
269+
`-- tags
270+
271+
20 directories, 10 files
272+
273+
$ cat ${TESTTMP}/josh-proxy.out

0 commit comments

Comments
 (0)