Skip to content

Commit feb62a4

Browse files
christian-schillingLMG
authored andcommitted
Skip empty commits on push
This happens when pushing to a remote with an ::exclude[...] and adding local files to the repo that are not supposed to be pushed. Previously this resulted in commits with empty diffs. Change: skip-empty-push
1 parent 5c41263 commit feb62a4

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/history.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,17 @@ pub fn unapply_filter(
511511
false,
512512
)?;
513513

514-
if let Some(ref mut change_ids) = change_ids {
515-
change_ids.push(get_change_id(&module_commit, ret));
516-
}
514+
ret = if original_parents_refs.len() == 1
515+
&& new_tree.id() == original_parents_refs[0].tree_id()
516+
&& Some(module_commit.tree_id()) != module_commit.parents().next().map(|x| x.tree_id())
517+
{
518+
original_parents_refs[0].id()
519+
} else {
520+
if let Some(ref mut change_ids) = change_ids {
521+
change_ids.push(get_change_id(&module_commit, ret));
522+
}
523+
ret
524+
};
517525

518526
bm.insert(module_commit.id(), ret);
519527
}

tests/filter/reverse_hide.t

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,22 @@
5959
* add sub1/file3
6060
* add file2
6161
* add file1
62+
63+
$ git checkout hidden 1> /dev/null
64+
Switched to branch 'hidden'
65+
66+
$ mkdir sub2
67+
$ echo contents4 > sub2/file4
68+
$ git add sub2/file4
69+
$ git commit -m "add sub2/file4" 1> /dev/null
70+
$ git commit -m "empty commit" --allow-empty 1> /dev/null
71+
72+
$ josh-filter -s :exclude[::sub2/] --reverse master --update refs/heads/hidden
73+
[1] :prefix=sub2
74+
[2] :/sub2
75+
[2] :exclude[::sub2/]
76+
$ git log --graph --pretty=%s refs/heads/master
77+
* empty commit
78+
* add sub1/file3
79+
* add file2
80+
* add file1

0 commit comments

Comments
 (0)