Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Documentation/git-absorb.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ https://stackoverflow.com/a/29094904[GIT_SEQUENCE_EDITOR] environment
variable if you don't need to edit the rebase TODO file.

4. If you are not satisfied (or if something bad happened), `git reset
--soft` to the pre-absorption commit to recover your old state. (You can
find the commit in question with `git reflog`.) And if you think
`git absorb` is at fault, please
--soft PRE_ABSORB_HEAD` to the pre-absorption commit to recover your old
state. (You can also find the commit in question with `git reflog`.) And
if you think `git absorb` is at fault, please
https://github.com/tummychow/git-absorb/issues/new[file an issue].

CONFIGURATION
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Note: `cargo install` does not currently know how to install manpages ([cargo#27
1. `git add` any changes that you want to absorb. By design, `git absorb` will only consider content in the git index (staging area).
2. `git absorb`. This will create a sequence of commits on `HEAD`. Each commit will have a `fixup!` message indicating the message (if unique) or SHA of the commit it should be squashed into.
3. If you are satisfied with the output, `git rebase -i --autosquash` to squash the `fixup!` commits into their predecessors. You can set the [`GIT_SEQUENCE_EDITOR`](https://stackoverflow.com/a/29094904) environment variable if you don't need to edit the rebase TODO file.
4. If you are not satisfied (or if something bad happened), `git reset --soft` to the pre-absorption commit to recover your old state. (You can find the commit in question with `git reflog`.) And if you think `git absorb` is at fault, please [file an issue](https://github.com/tummychow/git-absorb/issues/new).
4. If you are not satisfied (or if something bad happened), `git reset --soft PRE_ABSORB_HEAD` will reset to the pre-absorption commit and recover your old state. (You can also find the commit in question with `git reflog`.) And if you think `git absorb` is at fault, please [file an issue](https://github.com/tummychow/git-absorb/issues/new).

## How it works (roughly)

Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ fn run_with_repo(logger: &slog::Logger, config: &Config, repo: &git2::Repository

let target_always_sha: bool = config::fixup_target_always_sha(repo);

if !config.dry_run {
repo.reference("PRE_ABSORB_HEAD", head_commit.id(), true, "")?;
}

// * apply all hunks that are going to be fixed up into `dest_commit`
// * commit the fixup
// * repeat for all `dest_commit`s
Expand Down Expand Up @@ -525,6 +529,8 @@ mod tests {
fn multiple_fixups_per_commit() {
let ctx = repo_utils::prepare_and_stage();

let actual_pre_absorb_commit = ctx.repo.head().unwrap().peel_to_commit().unwrap().id();

// run 'git-absorb'
let drain = slog::Discard;
let logger = slog::Logger::root(drain, o!());
Expand All @@ -535,6 +541,9 @@ mod tests {
assert_eq!(revwalk.count(), 3);

assert!(nothing_left_in_index(&ctx.repo).unwrap());

let pre_absorb_ref_commit = ctx.repo.refname_to_id("PRE_ABSORB_HEAD").unwrap();
assert_eq!(pre_absorb_ref_commit, actual_pre_absorb_commit);
}

#[test]
Expand Down Expand Up @@ -803,6 +812,9 @@ mod tests {
assert_eq!(revwalk.count(), 1);
let is_something_in_index = !nothing_left_in_index(&ctx.repo).unwrap();
assert!(is_something_in_index);

let pre_absorb_ref_commit = ctx.repo.references_glob("PRE_ABSORB_HEAD").unwrap().last();
assert!(matches!(pre_absorb_ref_commit, None));
}

#[test]
Expand Down