Skip to content

Commit d707b11

Browse files
chf2117cshinaver
andauthored
fix(hooks): post-rewrite hook does not track intermediate commits from an interactive rebase ((#1088, #1419)
* (#1088) post-rewrite hook does not track intermediate commits from a rebase * Remove additions to testing API --------- Co-authored-by: cshinaver <[email protected]> Co-authored-by: Caleb Fujimori <[email protected]>
1 parent 8238d0b commit d707b11

File tree

3 files changed

+43
-33
lines changed

3 files changed

+43
-33
lines changed

git-branchless-hook/tests/test_hook.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ fn test_rebase_no_process_new_commits_until_conclusion() -> eyre::Result<()> {
105105
insta::assert_snapshot!(stdout, @"");
106106
}
107107

108-
git.commit_file("test4", 4)?;
109108
{
110109
let (stdout, stderr) = git.run(&["rebase", "--continue"])?;
111110
insta::assert_snapshot!(stderr, @r###"
@@ -133,8 +132,6 @@ fn test_rebase_no_process_new_commits_until_conclusion() -> eyre::Result<()> {
133132
O f777ecc (master) create initial.txt
134133
|\
135134
| o 047b7ad create test1.txt
136-
| |
137-
| o ecab41f create test4.txt
138135
|
139136
x 62fc20d (rewritten as 047b7ad7) create test1.txt
140137
|

git-branchless-lib/src/core/rewrite/rewrite_hooks.rs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
use std::collections::{HashMap, HashSet};
44

55
use std::fmt::Write;
6-
use std::fs::{self, File};
7-
use std::io::{self, stdin, BufRead, BufReader, Read, Write as WriteIo};
6+
use std::fs::File;
7+
use std::io::{stdin, BufRead, BufReader, Read, Write as WriteIo};
88
use std::path::{Path, PathBuf};
9-
use std::str::FromStr;
109
use std::time::SystemTime;
1110

1211
use console::style;
@@ -44,20 +43,6 @@ pub fn get_deferred_commits_path(repo: &Repo) -> PathBuf {
4443
repo.get_rebase_state_dir_path().join("deferred-commits")
4544
}
4645

47-
fn read_deferred_commits(repo: &Repo) -> eyre::Result<Vec<NonZeroOid>> {
48-
let deferred_commits_path = get_deferred_commits_path(repo);
49-
let contents = match fs::read_to_string(&deferred_commits_path) {
50-
Ok(contents) => contents,
51-
Err(err) if err.kind() == io::ErrorKind::NotFound => Default::default(),
52-
Err(err) => {
53-
return Err(err)
54-
.with_context(|| format!("Reading deferred commits at {deferred_commits_path:?}"))
55-
}
56-
};
57-
let commit_oids = contents.lines().map(NonZeroOid::from_str).try_collect()?;
58-
Ok(commit_oids)
59-
}
60-
6146
#[instrument(skip(stream))]
6247
fn read_rewritten_list_entries(
6348
stream: &mut impl Read,
@@ -148,19 +133,6 @@ pub fn hook_post_rewrite(
148133
let event_log_db = EventLogDb::new(&conn)?;
149134
let event_tx_id = event_log_db.make_transaction_id(now, "hook-post-rewrite")?;
150135

151-
{
152-
let deferred_commit_oids = read_deferred_commits(&repo)?;
153-
let commit_events = deferred_commit_oids
154-
.into_iter()
155-
.map(|commit_oid| Event::CommitEvent {
156-
timestamp,
157-
event_tx_id,
158-
commit_oid,
159-
})
160-
.collect_vec();
161-
event_log_db.add_events(commit_events)?;
162-
}
163-
164136
let (rewritten_oids, rewrite_events) = {
165137
let rewritten_oids = read_rewritten_list_entries(&mut stdin().lock())?;
166138
let events = rewritten_oids

git-branchless/tests/test_hooks.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,5 +411,46 @@ fn test_symbolic_transaction_ref() -> eyre::Result<()> {
411411
branchless: processing checkout
412412
"###);
413413
}
414+
415+
Ok(())
416+
}
417+
418+
#[cfg(unix)]
419+
#[test]
420+
fn test_git_rebase_multiple_fixup_does_not_strand_commits() -> eyre::Result<()> {
421+
let git = make_git()?;
422+
git.init_repo()?;
423+
424+
git.detach_head()?;
425+
426+
git.write_file("test1.txt", "bleh")?;
427+
git.run(&["add", "."])?;
428+
git.run(&["commit", "-m", "create test1.txt"])?;
429+
git.write_file("test2.txt", "bleh")?;
430+
git.run(&["add", "."])?;
431+
git.run(&["commit", "-m", "fixup! create test1.txt"])?;
432+
git.write_file("test3.txt", "bleh")?;
433+
git.run(&["add", "."])?;
434+
git.run(&["commit", "-m", "fixup! create test1.txt"])?;
435+
git.write_file("test3.txt", "bleh")?;
436+
437+
git.run(&[
438+
"-c",
439+
"sequence.editor=:",
440+
"rebase",
441+
"-i",
442+
"--autosquash",
443+
"master",
444+
])?;
445+
446+
{
447+
let stdout = git.smartlog()?;
448+
insta::assert_snapshot!(stdout, @r###"
449+
O f777ecc (master) create initial.txt
450+
|
451+
@ 8777bab create test1.txt
452+
"###);
453+
}
454+
414455
Ok(())
415456
}

0 commit comments

Comments
 (0)