Skip to content

Commit a4188e5

Browse files
Fix :squash() for histories containing an empty orphan (#1350)
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 a4188e5

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

0 commit comments

Comments
 (0)