Skip to content

Commit d846e22

Browse files
committed
fix: Do not use 3way merged checks
When checking for already merged patches, i.e. with `stg push --merged` or `stg pull --merged`, using 3way patch application creates false-positives such that StGit would wrongly believe that a patch was already integrated upstream. This would then lead to the pushed patch becoming empty--which is bad. Using non-3way patch application for the already-merged checks solves this problem.
1 parent 938c295 commit d846e22

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

src/cmd/refresh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ fn run(matches: &ArgMatches) -> Result<()> {
283283

284284
if let Some(tree_id) = repo.stupid().with_temp_index(|stupid_temp| {
285285
stupid_temp.read_tree(ours)?;
286-
if stupid_temp.apply_treediff_to_index(base, theirs)? {
286+
if stupid_temp.apply_treediff_to_index(base, theirs, true)? {
287287
let tree_id = stupid_temp.write_tree()?;
288288
Ok(Some(tree_id))
289289
} else {

src/cmd/spill.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ fn run(matches: &ArgMatches) -> Result<()> {
8686
stupid_temp.apply_pathlimited_treediff_to_index(
8787
patch_commit.tree_id(),
8888
parent.tree_id(),
89+
true,
8990
pathspecs,
9091
)?;
9192
stupid_temp.write_tree()

src/cmd/squash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ fn try_squash(
234234
for commit in patchnames[1..].iter().map(|pn| trans.get_patch_commit(pn)) {
235235
let parent = commit.parent(0)?;
236236
if parent.tree_id() != commit.tree_id()
237-
&& !stupid_temp.apply_treediff_to_index(parent.tree_id(), commit.tree_id())?
237+
&& !stupid_temp.apply_treediff_to_index(parent.tree_id(), commit.tree_id(), true)?
238238
{
239239
return Ok(None);
240240
}

src/stack/transaction/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ impl<'repo> StackTransaction<'repo> {
967967
*temp_index_tree_id = Some(ours);
968968
}
969969

970-
let maybe_tree_id = if stupid_temp.apply_treediff_to_index(base, theirs)? {
970+
let maybe_tree_id = if stupid_temp.apply_treediff_to_index(base, theirs, true)? {
971971
stupid_temp.write_tree().ok()
972972
} else {
973973
None
@@ -1103,9 +1103,11 @@ impl<'repo> StackTransaction<'repo> {
11031103

11041104
let parent_commit = patch_commit.parent(0)?;
11051105

1106-
if stupid_temp
1107-
.apply_treediff_to_index(patch_commit.tree_id(), parent_commit.tree_id())?
1108-
{
1106+
if stupid_temp.apply_treediff_to_index(
1107+
patch_commit.tree_id(),
1108+
parent_commit.tree_id(),
1109+
false,
1110+
)? {
11091111
merged.push(patchname);
11101112
*temp_index_tree_id = None;
11111113
}

src/stupid/mod.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ impl<'repo, 'index> StupidContext<'repo, 'index> {
151151
&self,
152152
tree1: git2::Oid,
153153
tree2: git2::Oid,
154+
do_3way: bool,
154155
) -> Result<bool> {
155156
if tree1 == tree2 {
156157
return Ok(true);
@@ -165,9 +166,12 @@ impl<'repo, 'index> StupidContext<'repo, 'index> {
165166
.stdout(Stdio::piped())
166167
.spawn_git()?;
167168

168-
let apply_output = self
169-
.git_in_work_root()
170-
.args(["apply", "--cached", "--3way"])
169+
let mut apply_cmd = self.git_in_work_root();
170+
apply_cmd.args(["apply", "--cached"]);
171+
if do_3way {
172+
apply_cmd.arg("--3way");
173+
}
174+
let apply_output = apply_cmd
171175
.stdin(diff_tree_child.stdout.take().unwrap())
172176
.stdout(Stdio::null())
173177
.output_git()?
@@ -182,6 +186,7 @@ impl<'repo, 'index> StupidContext<'repo, 'index> {
182186
&self,
183187
tree1: git2::Oid,
184188
tree2: git2::Oid,
189+
do_3way: bool,
185190
pathspecs: SpecIter,
186191
) -> Result<bool>
187192
where
@@ -210,9 +215,12 @@ impl<'repo, 'index> StupidContext<'repo, 'index> {
210215
return Ok(true);
211216
}
212217

213-
let apply_output = self
214-
.git_in_work_root()
215-
.args(["apply", "--cached", "--3way"])
218+
let mut apply_cmd = self.git_in_work_root();
219+
apply_cmd.args(["apply", "--cached"]);
220+
if do_3way {
221+
apply_cmd.arg("--3way");
222+
}
223+
let apply_output = apply_cmd
216224
.stdin(Stdio::piped())
217225
.stdout(Stdio::null())
218226
.in_and_out(&diff)?;

0 commit comments

Comments
 (0)