-
Notifications
You must be signed in to change notification settings - Fork 93
Add --one-reflog-entry option #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ mod config; | |
| mod owned; | ||
| mod stack; | ||
|
|
||
| use git2::ResetType; | ||
| use std::io::Write; | ||
| use std::path::Path; | ||
|
|
||
|
|
@@ -19,6 +20,7 @@ pub struct Config<'a> { | |
| pub rebase_options: &'a Vec<&'a str>, | ||
| pub whole_file: bool, | ||
| pub one_fixup_per_commit: bool, | ||
| pub one_reflog_entry: bool, | ||
| } | ||
|
|
||
| pub fn run(logger: &slog::Logger, config: &Config) -> Result<()> { | ||
|
|
@@ -316,7 +318,7 @@ fn run_with_repo(logger: &slog::Logger, config: &Config, repo: &git2::Repository | |
| if !config.dry_run { | ||
| head_tree = new_head_tree; | ||
| head_commit = repo.find_commit(repo.commit( | ||
| Some("HEAD"), | ||
| (!config.one_reflog_entry).then_some("HEAD"), | ||
| &signature, | ||
| &signature, | ||
| &format!("fixup! {}\n", dest_commit_locator), | ||
|
|
@@ -339,6 +341,14 @@ fn run_with_repo(logger: &slog::Logger, config: &Config, repo: &git2::Repository | |
| } | ||
| } | ||
|
|
||
| if config.one_reflog_entry && !config.dry_run { | ||
| let mut head_ref = repo.head()?; | ||
| head_ref.set_target(head_commit.id(), "absorb: adding fixup commits")?; | ||
| // If you don't like the fancy custom reflog message above and want to stick to Git's own | ||
| // messages, this would also work: | ||
| // repo.reset(head_commit.as_object(), ResetType::Soft, None)?; | ||
| } | ||
|
|
||
|
Comment on lines
+344
to
+351
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: This almost definitely doesn't work in combination with Or would it be fine to just make
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or, another idea: Call the option |
||
| if autostage_enabled && we_added_everything_to_index { | ||
| // now that the fixup commits have been created, | ||
| // we should unstage the remaining changes from the index. | ||
|
|
@@ -557,6 +567,39 @@ mod tests { | |
| assert!(nothing_left_in_index(&ctx.repo).unwrap()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn one_reflog_entry() { | ||
| let ctx = repo_utils::prepare_and_stage(); | ||
|
|
||
| // get initial reflog length to compare | ||
| let initial_reflog_len = ctx.repo.reflog("HEAD").unwrap().len(); | ||
|
|
||
| // run 'git-absorb' | ||
| let drain = slog::Discard; | ||
| let logger = slog::Logger::root(drain, o!()); | ||
| let config = Config { | ||
| one_reflog_entry: true, | ||
| ..DEFAULT_CONFIG | ||
| }; | ||
| run_with_repo(&logger, &config, &ctx.repo).unwrap(); | ||
|
|
||
| // sanity checks: all is as usual when it comes to commits and index: | ||
| let mut revwalk = ctx.repo.revwalk().unwrap(); | ||
| revwalk.push_head().unwrap(); | ||
| assert_eq!(revwalk.count(), 3); | ||
| assert!(nothing_left_in_index(&ctx.repo).unwrap()); | ||
|
Comment on lines
+586
to
+590
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just copied this from the |
||
|
|
||
| // check that only one reflog entry was created: | ||
| let reflog = ctx.repo.reflog("HEAD").unwrap(); | ||
| let final_reflog_len = reflog.len(); | ||
| assert_eq!(final_reflog_len, initial_reflog_len + 1); | ||
|
|
||
| // check reflog entry message: | ||
| let reflog_entry = reflog.get(0).unwrap(); | ||
| let reflog_message = reflog_entry.message().unwrap(); | ||
| assert_eq!(reflog_message, "absorb: adding fixup commits"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn foreign_author() { | ||
| let ctx = repo_utils::prepare_and_stage(); | ||
|
|
@@ -973,5 +1016,6 @@ mod tests { | |
| rebase_options: &Vec::new(), | ||
| whole_file: false, | ||
| one_fixup_per_commit: false, | ||
| one_reflog_entry: false, | ||
| }; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If everything else is fine, an opinion would be needed here.