Skip to content

Commit 68b2300

Browse files
Fix :squash() for histories containing an empty orphan
The implementation relied on the orphan commit being dropped by the normal drop rules, but those have an exception to keep empty trees. Change: squash-empty-orphan
1 parent 4a6eec2 commit 68b2300

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+113
-66
lines changed

josh-core/src/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::*;
22
use std::collections::HashMap;
33

4-
const CACHE_VERSION: u64 = 20;
4+
const CACHE_VERSION: u64 = 21;
55

66
lazy_static! {
77
static ref DB: std::sync::Mutex<Option<sled::Db>> = std::sync::Mutex::new(None);

josh-core/src/filter/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,12 @@ fn apply_to_commit2(
741741
},
742742
);
743743
}
744-
tree::empty(repo)
744+
return Ok(Some(history::drop_commit(
745+
commit,
746+
vec![],
747+
transaction,
748+
filter,
749+
)?));
745750
}
746751
}
747752
Op::Linear => {

tests/filter/squash.t

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030

3131
$ josh-filter -s --squash-pattern "refs/tags/*" --update refs/heads/filtered
3232
Warning: reference refs/heads/filtered wasn't updated
33-
[1] :squash(
34-
35-
)
3633

3734
$ git log --graph --decorate --pretty=oneline refs/heads/filtered
3835
fatal: ambiguous argument 'refs/heads/filtered': unknown revision or path not in the working tree.
@@ -45,9 +42,6 @@ This one tag is an annotated tag, to make sure those are handled as well
4542
$ josh-filter -s --squash-pattern "refs/tags/*" :author=\"New\ Author\"\;\"new@e.mail\" --update refs/heads/filtered
4643
[1] :author="New Author";"new@e.mail"
4744
[1] :squash(
48-
49-
)
50-
[2] :squash(
5145
1d69b7d2651f744be3416f2ad526aeccefb99310:"refs/tags/tag_a"
5246
)
5347
@@ -67,9 +61,6 @@ This one tag is an annotated tag, to make sure those are handled as well
6761
6862
$ josh-filter -s --squash-pattern "refs/tags/*" :author=\"New\ Author\"\;\"new@e.mail\" --update refs/heads/filtered
6963
[1] :squash(
70-
71-
)
72-
[2] :squash(
7364
1d69b7d2651f744be3416f2ad526aeccefb99310:"refs/tags/tag_a"
7465
)
7566
[3] :squash(
@@ -124,9 +115,6 @@ This one tag is an annotated tag, to make sure those are handled as well
124115
):author="New Author";"new@e.mail"
125116
$ josh-filter -s --file filter.josh --update refs/heads/filtered
126117
[1] :squash(
127-
128-
)
129-
[2] :squash(
130118
1d69b7d2651f744be3416f2ad526aeccefb99310:"refs/tags/tag_a"
131119
)
132120
[3] :squash(

tests/filter/squash_empty_initial.t

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
$ export RUST_BACKTRACE=1
2+
$ git init -q 1> /dev/null
3+
4+
$ git commit -m "Empty initial" --allow-empty 1> /dev/null
5+
6+
$ git log --graph --pretty=%s
7+
* Empty initial
8+
9+
$ git checkout -b branch2
10+
Switched to a new branch 'branch2'
11+
12+
$ echo contents2 > file1
13+
$ git add .
14+
$ git commit -m "mod file1" 1> /dev/null
15+
16+
$ echo contents3 > file3
17+
$ git add .
18+
$ git commit -m "mod file3" 1> /dev/null
19+
20+
$ git checkout master
21+
Switched to branch 'master'
22+
23+
$ echo contents3 > file2
24+
$ git add .
25+
$ git commit -m "add file2" 1> /dev/null
26+
27+
$ git merge -q branch2 --no-ff
28+
29+
$ git log --graph --decorate --pretty=oneline
30+
* 882f2656a5075936eb37bfefde740e0b453e4479 (HEAD -> master) Merge branch 'branch2'
31+
|\
32+
| * 87bb87b63d1745136cb2ea167ef3ffc82c7ef3f0 (branch2) mod file3
33+
| * 2db14eafe99deeeab5db07bf33e332d523a298ab mod file1
34+
* | 54d8f704681c3b44a468cef655fa3b5bc5229a4c add file2
35+
|/
36+
* 8c26fa0172bda17bafcbcf9684e639c6b0bae9c4 Empty initial
37+
38+
$ josh-filter -s --squash-pattern "refs/tags/*" --update refs/heads/filtered
39+
Warning: reference refs/heads/filtered wasn't updated
40+
$ git log --graph --decorate --pretty=oneline refs/heads/filtered
41+
fatal: ambiguous argument 'refs/heads/filtered': unknown revision or path not in the working tree.
42+
Use '--' to separate paths from revisions, like this:
43+
'git <command> [<revision>...] -- [<file>...]'
44+
[128]
45+
46+
$ git tag -a tag_a -m "created a tag" 882f2656a5075936eb37bfefde740e0b453e4479
47+
$ josh-filter -s --squash-pattern "refs/tags/*" :author=\"New\ Author\"\;\"new@e.mail\" --update refs/heads/filtered
48+
[1] :author="New Author";"new@e.mail"
49+
[1] :squash(
50+
882f2656a5075936eb37bfefde740e0b453e4479:"refs/tags/tag_a"
51+
)
52+
53+
$ git log --graph --decorate --pretty=oneline refs/heads/filtered
54+
* d8aa5a9937f4f0bd645dbc0b591bae5cd6b6d91b (tag: filtered/tag_a, filtered) refs/tags/tag_a

tests/proxy/amend_patchset.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
]
125125
.
126126
|-- josh
127-
| `-- 20
127+
| `-- 21
128128
| `-- sled
129129
| |-- blobs
130130
| |-- conf

tests/proxy/authentication.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"real_repo.git" = ["::sub1/"]
125125
.
126126
|-- josh
127-
| `-- 20
127+
| `-- 21
128128
| `-- sled
129129
| |-- blobs
130130
| |-- conf

tests/proxy/caching.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
]
5252
.
5353
|-- josh
54-
| `-- 20
54+
| `-- 21
5555
| `-- sled
5656
| |-- blobs
5757
| |-- conf
@@ -162,7 +162,7 @@
162162
]
163163
.
164164
|-- josh
165-
| `-- 20
165+
| `-- 21
166166
| `-- sled
167167
| |-- blobs
168168
| |-- conf

tests/proxy/clone_absent_head.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
$ bash ${TESTDIR}/destroy_test_env.sh
8686
.
8787
|-- josh
88-
| `-- 20
88+
| `-- 21
8989
| `-- sled
9090
| |-- blobs
9191
| |-- conf

tests/proxy/clone_all.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"real_repo.git" = ["::sub1/"]
5454
.
5555
|-- josh
56-
| `-- 20
56+
| `-- 21
5757
| `-- sled
5858
| |-- blobs
5959
| |-- conf

tests/proxy/clone_blocked.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
$ bash ${TESTDIR}/destroy_test_env.sh
1010
.
1111
|-- josh
12-
| `-- 20
12+
| `-- 21
1313
| `-- sled
1414
| |-- blobs
1515
| |-- conf

tests/proxy/clone_invalid_url.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
$ bash ${TESTDIR}/destroy_test_env.sh
3333
.
3434
|-- josh
35-
| `-- 20
35+
| `-- 21
3636
| `-- sled
3737
| |-- blobs
3838
| |-- conf

tests/proxy/clone_locked_refs.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
]
112112
.
113113
|-- josh
114-
| `-- 20
114+
| `-- 21
115115
| `-- sled
116116
| |-- blobs
117117
| |-- conf

tests/proxy/clone_prefix.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
]
7575
.
7676
|-- josh
77-
| `-- 20
77+
| `-- 21
7878
| `-- sled
7979
| |-- blobs
8080
| |-- conf

tests/proxy/clone_sha.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Check (2) and (3) but with a branch ref
9393
"real_repo.git" = ["::sub1/"]
9494
.
9595
|-- josh
96-
| `-- 20
96+
| `-- 21
9797
| `-- sled
9898
| |-- blobs
9999
| |-- conf

tests/proxy/clone_subsubtree.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
]
8888
.
8989
|-- josh
90-
| `-- 20
90+
| `-- 21
9191
| `-- sled
9292
| |-- blobs
9393
| |-- conf

tests/proxy/clone_subtree.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
]
8686
.
8787
|-- josh
88-
| `-- 20
88+
| `-- 21
8989
| `-- sled
9090
| |-- blobs
9191
| |-- conf

tests/proxy/clone_subtree_no_master.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"real_repo.git" = [":/sub1"]
7979
.
8080
|-- josh
81-
| `-- 20
81+
| `-- 21
8282
| `-- sled
8383
| |-- blobs
8484
| |-- conf

tests/proxy/clone_subtree_tags.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
]
116116
.
117117
|-- josh
118-
| `-- 20
118+
| `-- 21
119119
| `-- sled
120120
| |-- blobs
121121
| |-- conf

tests/proxy/clone_with_meta.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
]
130130
.
131131
|-- josh
132-
| `-- 20
132+
| `-- 21
133133
| `-- sled
134134
| |-- blobs
135135
| |-- conf

tests/proxy/empty_commit.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ should still be included.
8383
"real_repo.git" = ["::sub1/"]
8484
.
8585
|-- josh
86-
| `-- 20
86+
| `-- 21
8787
| `-- sled
8888
| |-- blobs
8989
| |-- conf

tests/proxy/get_version.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
$ bash ${TESTDIR}/destroy_test_env.sh
88
.
99
|-- josh
10-
| `-- 20
10+
| `-- 21
1111
| `-- sled
1212
| |-- blobs
1313
| |-- conf

tests/proxy/import_export.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ Flushed credential cache
301301
"repo2.git" = [":prefix=repo2"]
302302
.
303303
|-- josh
304-
| `-- 20
304+
| `-- 21
305305
| `-- sled
306306
| |-- blobs
307307
| |-- conf

tests/proxy/join_subtree.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Make sure all temporary namespace got removed
132132
]
133133
.
134134
|-- josh
135-
| `-- 20
135+
| `-- 21
136136
| `-- sled
137137
| |-- blobs
138138
| |-- conf

tests/proxy/join_with_merge.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"real_repo.git" = [":prefix=sub1"]
6060
.
6161
|-- josh
62-
| `-- 20
62+
| `-- 21
6363
| `-- sled
6464
| |-- blobs
6565
| |-- conf

tests/proxy/markers.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@
340340
]
341341
.
342342
|-- josh
343-
| `-- 20
343+
| `-- 21
344344
| `-- sled
345345
| |-- blobs
346346
| |-- conf

tests/proxy/no_proxy.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
$ bash ${TESTDIR}/destroy_test_env.sh
3636
.
3737
|-- josh
38-
| `-- 20
38+
| `-- 21
3939
| `-- sled
4040
| |-- blobs
4141
| |-- conf

tests/proxy/no_proxy_lfs.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
$ bash ${TESTDIR}/destroy_test_env.sh
5151
.
5252
|-- josh
53-
| `-- 20
53+
| `-- 21
5454
| `-- sled
5555
| |-- blobs
5656
| |-- conf

tests/proxy/push_graphql.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"real_repo.git" = ["::sub1/"]
7070
.
7171
|-- josh
72-
| `-- 20
72+
| `-- 21
7373
| `-- sled
7474
| |-- blobs
7575
| |-- conf

tests/proxy/push_new_branch.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Check the branch again
114114
]
115115
.
116116
|-- josh
117-
| `-- 20
117+
| `-- 21
118118
| `-- sled
119119
| |-- blobs
120120
| |-- conf

tests/proxy/push_prefix.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
]
5757
.
5858
|-- josh
59-
| `-- 20
59+
| `-- 21
6060
| `-- sled
6161
| |-- blobs
6262
| |-- conf

tests/proxy/push_review.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Make sure all temporary namespace got removed
8787
]
8888
.
8989
|-- josh
90-
| `-- 20
90+
| `-- 21
9191
| `-- sled
9292
| |-- blobs
9393
| |-- conf

tests/proxy/push_review_already_in.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ test for that.
4848
"real_repo.git" = []
4949
.
5050
|-- josh
51-
| `-- 20
51+
| `-- 21
5252
| `-- sled
5353
| |-- blobs
5454
| |-- conf

tests/proxy/push_review_nop_behind.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ This is a regression test for that problem.
5555
"real_repo.git" = []
5656
.
5757
|-- josh
58-
| `-- 20
58+
| `-- 21
5959
| `-- sled
6060
| |-- blobs
6161
| |-- conf

tests/proxy/push_review_old.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Flushed credential cache
8585
]
8686
.
8787
|-- josh
88-
| `-- 20
88+
| `-- 21
8989
| `-- sled
9090
| |-- blobs
9191
| |-- conf

0 commit comments

Comments
 (0)