Skip to content

Commit 7bdefb1

Browse files
christian-schillingLMG
authored andcommitted
Fix broken handling of merges on push
With #994 a bug was introduced where merge commits where not handled correctly in case they include changes that are not a result of merging the two parents. Those changes would simply be discarded. Change: fix-merge-push
1 parent 58d17f6 commit 7bdefb1

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/history.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,14 @@ pub fn unapply_filter(
491491
) {
492492
// If we can auto merge without conflicts, take the result.
493493
if !merged_index.has_conflicts() {
494-
tid = merged_index.write_tree_to(transaction.repo())?;
494+
let base_tree = merged_index.write_tree_to(transaction.repo())?;
495+
tid = filter::unapply(
496+
transaction,
497+
filterobj,
498+
tree,
499+
transaction.repo().find_tree(base_tree)?,
500+
)?
501+
.id();
495502
}
496503
}
497504
}

tests/filter/subtree_prefix.t

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,51 @@ And finally, sync first from main to sub and then back.
207207
file1
208208
subtree/file2
209209
subtree/subfeature1
210+
211+
$ git checkout subtree
212+
Already on 'subtree'
213+
214+
Create an extra file and amend the merge commit to include it, then check it is also
215+
taken back into the main history.
216+
$ echo "random stuff" > a_file
217+
$ git add a_file
218+
$ git commit --amend --no-edit
219+
[subtree bab52d5] Merge branch 'subtree-sync' into subtree
220+
Date: Thu Apr 7 22:13:13 2005 +0000
221+
$ git checkout master
222+
Switched to branch 'master'
223+
224+
$ josh-filter -s ":rev($SUBTREE_TIP:prefix=subtree):/subtree" refs/heads/master --update refs/heads/subtree --reverse
225+
[1] :prefix=subtree
226+
[13] :/subtree
227+
[13] :rev(c036f944faafb865e0585e4fa5e005afa0aeea3f:prefix=subtree)
228+
$ git ls-tree --name-only -r refs/heads/master
229+
feature1
230+
feature2
231+
file1
232+
subtree/a_file
233+
subtree/file2
234+
subtree/subfeature1
235+
subtree/subfeature2
236+
237+
$ git log --graph --pretty=%H:%s refs/heads/master
238+
* f814033dd0148da19a3199cd3cb2d21464ce85a3:Merge branch 'subtree-sync' into subtree
239+
|\
240+
| * 38a6d753c8b17b4c6721050befbccff012dfde85:Merge branch 'feature2'
241+
| |\
242+
| | * 221f5ceab31209c3d3b16d5b2485ea54c465eca6:feature2
243+
* | | 75e90f7f1b54cc343f2f75dcdee33650654a52a6:subfeature2
244+
* | | 3fa497039e5b384cb44b704e6e96f52e0ae599c9:Merge branch 'subtree-sync' into subtree
245+
|\| |
246+
| * | 2739fb8f0b3f6d5a264fb89ea20674fe34790321:Merge branch 'feature1'
247+
| |\ \
248+
| | * | dbfaf5dd32fc39ce3c0ebe61864406bb7e2ad113:feature1
249+
| | |/
250+
* | / 59b5c1623da3f89229c6dd36f8baf2e5868d0288:subfeature1
251+
|/ /
252+
* | 103bfec17c47adbe70a95fca90caefb989b6cda6:add even more content
253+
* | 41130c5d66736545562212f820cdbfbb3d3779c4:subtree edit from main repo
254+
* | 0642c36d6b53f7e829531aed848e3ceff0762c64:subtree merge
255+
|\|
256+
| * c036f944faafb865e0585e4fa5e005afa0aeea3f:add file2 (in subtree)
257+
* 0b4cf6c9efbbda1eada39fa9c1d21d2525b027bb:add file1

0 commit comments

Comments
 (0)