diff --git a/git-branchless-hook/tests/test_hook.rs b/git-branchless-hook/tests/test_hook.rs index 379cedb64..41c11c924 100644 --- a/git-branchless-hook/tests/test_hook.rs +++ b/git-branchless-hook/tests/test_hook.rs @@ -105,7 +105,6 @@ fn test_rebase_no_process_new_commits_until_conclusion() -> eyre::Result<()> { insta::assert_snapshot!(stdout, @""); } - git.commit_file("test4", 4)?; { let (stdout, stderr) = git.run(&["rebase", "--continue"])?; insta::assert_snapshot!(stderr, @r###" @@ -133,8 +132,6 @@ fn test_rebase_no_process_new_commits_until_conclusion() -> eyre::Result<()> { O f777ecc (master) create initial.txt |\ | o 047b7ad create test1.txt - | | - | o ecab41f create test4.txt | x 62fc20d (rewritten as 047b7ad7) create test1.txt | diff --git a/git-branchless-lib/src/core/rewrite/rewrite_hooks.rs b/git-branchless-lib/src/core/rewrite/rewrite_hooks.rs index 956693068..6651538ef 100644 --- a/git-branchless-lib/src/core/rewrite/rewrite_hooks.rs +++ b/git-branchless-lib/src/core/rewrite/rewrite_hooks.rs @@ -3,10 +3,9 @@ use std::collections::{HashMap, HashSet}; use std::fmt::Write; -use std::fs::{self, File}; -use std::io::{self, stdin, BufRead, BufReader, Read, Write as WriteIo}; +use std::fs::File; +use std::io::{stdin, BufRead, BufReader, Read, Write as WriteIo}; use std::path::{Path, PathBuf}; -use std::str::FromStr; use std::time::SystemTime; use console::style; @@ -44,20 +43,6 @@ pub fn get_deferred_commits_path(repo: &Repo) -> PathBuf { repo.get_rebase_state_dir_path().join("deferred-commits") } -fn read_deferred_commits(repo: &Repo) -> eyre::Result> { - let deferred_commits_path = get_deferred_commits_path(repo); - let contents = match fs::read_to_string(&deferred_commits_path) { - Ok(contents) => contents, - Err(err) if err.kind() == io::ErrorKind::NotFound => Default::default(), - Err(err) => { - return Err(err) - .with_context(|| format!("Reading deferred commits at {deferred_commits_path:?}")) - } - }; - let commit_oids = contents.lines().map(NonZeroOid::from_str).try_collect()?; - Ok(commit_oids) -} - #[instrument(skip(stream))] fn read_rewritten_list_entries( stream: &mut impl Read, @@ -148,19 +133,6 @@ pub fn hook_post_rewrite( let event_log_db = EventLogDb::new(&conn)?; let event_tx_id = event_log_db.make_transaction_id(now, "hook-post-rewrite")?; - { - let deferred_commit_oids = read_deferred_commits(&repo)?; - let commit_events = deferred_commit_oids - .into_iter() - .map(|commit_oid| Event::CommitEvent { - timestamp, - event_tx_id, - commit_oid, - }) - .collect_vec(); - event_log_db.add_events(commit_events)?; - } - let (rewritten_oids, rewrite_events) = { let rewritten_oids = read_rewritten_list_entries(&mut stdin().lock())?; let events = rewritten_oids diff --git a/git-branchless/tests/test_hooks.rs b/git-branchless/tests/test_hooks.rs index 09b98059f..f142d789a 100644 --- a/git-branchless/tests/test_hooks.rs +++ b/git-branchless/tests/test_hooks.rs @@ -411,5 +411,46 @@ fn test_symbolic_transaction_ref() -> eyre::Result<()> { branchless: processing checkout "###); } + + Ok(()) +} + +#[cfg(unix)] +#[test] +fn test_git_rebase_multiple_fixup_does_not_strand_commits() -> eyre::Result<()> { + let git = make_git()?; + git.init_repo()?; + + git.detach_head()?; + + git.write_file("test1.txt", "bleh")?; + git.run(&["add", "."])?; + git.run(&["commit", "-m", "create test1.txt"])?; + git.write_file("test2.txt", "bleh")?; + git.run(&["add", "."])?; + git.run(&["commit", "-m", "fixup! create test1.txt"])?; + git.write_file("test3.txt", "bleh")?; + git.run(&["add", "."])?; + git.run(&["commit", "-m", "fixup! create test1.txt"])?; + git.write_file("test3.txt", "bleh")?; + + git.run(&[ + "-c", + "sequence.editor=:", + "rebase", + "-i", + "--autosquash", + "master", + ])?; + + { + let stdout = git.smartlog()?; + insta::assert_snapshot!(stdout, @r###" + O f777ecc (master) create initial.txt + | + @ 8777bab create test1.txt + "###); + } + Ok(()) }