Skip to content

Commit 98ff3ac

Browse files
authored
Merge pull request #168 from sh-at-cs/fix-gh-157-pre-absorb-head-ref
Mark pre-absorb commit with PRE_ABSORB_HEAD ref
2 parents c9e90a8 + 1860baa commit 98ff3ac

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Documentation/git-absorb.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ https://stackoverflow.com/a/29094904[GIT_SEQUENCE_EDITOR] environment
115115
variable if you don't need to edit the rebase TODO file.
116116
117117
4. If you are not satisfied (or if something bad happened), `git reset
118-
--soft` to the pre-absorption commit to recover your old state. (You can
119-
find the commit in question with `git reflog`.) And if you think
120-
`git absorb` is at fault, please
118+
--soft PRE_ABSORB_HEAD` to the pre-absorption commit to recover your old
119+
state. (You can also find the commit in question with `git reflog`.) And
120+
if you think `git absorb` is at fault, please
121121
https://github.com/tummychow/git-absorb/issues/new[file an issue].
122122
123123
CONFIGURATION

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Note: `cargo install` does not currently know how to install manpages ([cargo#27
8383
1. `git add` any changes that you want to absorb. By design, `git absorb` will only consider content in the git index (staging area).
8484
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.
8585
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.
86-
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).
86+
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).
8787

8888
## How it works (roughly)
8989

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ fn run_with_repo(logger: &slog::Logger, config: &Config, repo: &git2::Repository
273273

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

276+
if !config.dry_run {
277+
repo.reference("PRE_ABSORB_HEAD", head_commit.id(), true, "")?;
278+
}
279+
276280
// * apply all hunks that are going to be fixed up into `dest_commit`
277281
// * commit the fixup
278282
// * repeat for all `dest_commit`s
@@ -525,6 +529,8 @@ mod tests {
525529
fn multiple_fixups_per_commit() {
526530
let ctx = repo_utils::prepare_and_stage();
527531

532+
let actual_pre_absorb_commit = ctx.repo.head().unwrap().peel_to_commit().unwrap().id();
533+
528534
// run 'git-absorb'
529535
let drain = slog::Discard;
530536
let logger = slog::Logger::root(drain, o!());
@@ -535,6 +541,9 @@ mod tests {
535541
assert_eq!(revwalk.count(), 3);
536542

537543
assert!(nothing_left_in_index(&ctx.repo).unwrap());
544+
545+
let pre_absorb_ref_commit = ctx.repo.refname_to_id("PRE_ABSORB_HEAD").unwrap();
546+
assert_eq!(pre_absorb_ref_commit, actual_pre_absorb_commit);
538547
}
539548

540549
#[test]
@@ -805,6 +814,9 @@ mod tests {
805814
assert_eq!(revwalk.count(), 1);
806815
let is_something_in_index = !nothing_left_in_index(&ctx.repo).unwrap();
807816
assert!(is_something_in_index);
817+
818+
let pre_absorb_ref_commit = ctx.repo.references_glob("PRE_ABSORB_HEAD").unwrap().last();
819+
assert!(matches!(pre_absorb_ref_commit, None));
808820
}
809821

810822
#[test]

0 commit comments

Comments
 (0)