Skip to content

Commit 34d5ba2

Browse files
committed
Add forceDetach configuration option to always bypass detached HEAD check
1 parent 98c9098 commit 34d5ba2

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

Documentation/git-absorb.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,18 @@ edit your local or global `.gitconfig` and add the following section:
190190
forceAuthor = true
191191
.............................................................................
192192

193+
GENERATE FIXUPS ON DETACHED HEAD
194+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
195+
196+
By default, git-absorb will not generate fixup commits when HEAD is not a
197+
branch ("is detached"). To always generate fixups on detached HEADs,
198+
edit your local or global `.gitconfig` and add the following section:
199+
200+
.............................................................................
201+
[absorb]
202+
forceDetach = true
203+
.............................................................................
204+
193205
GITHUB PROJECT
194206
--------------
195207

src/config.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ pub const MAX_STACK: usize = 10;
77
pub const FORCE_AUTHOR_CONFIG_NAME: &str = "absorb.forceAuthor";
88
pub const FORCE_AUTHOR_DEFAULT: bool = false;
99

10+
pub const FORCE_DETACH_CONFIG_NAME: &str = "absorb.forceDetach";
11+
pub const FORCE_DETACH_DEFAULT: bool = false;
12+
1013
pub const ONE_FIXUP_PER_COMMIT_CONFIG_NAME: &str = "absorb.oneFixupPerCommit";
1114
pub const ONE_FIXUP_PER_COMMIT_DEFAULT: bool = false;
1215

@@ -36,7 +39,9 @@ pub fn unify<'config>(config: &'config Config, repo: &Repository) -> Config<'con
3639
force_author: config.force_author
3740
|| config.force
3841
|| bool_value(&repo, FORCE_AUTHOR_CONFIG_NAME, FORCE_AUTHOR_DEFAULT),
39-
force_detach: config.force_detach || config.force,
42+
force_detach: config.force_detach
43+
|| config.force
44+
|| bool_value(&repo, FORCE_DETACH_CONFIG_NAME, FORCE_DETACH_DEFAULT),
4045
..*config
4146
}
4247
}

src/lib.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -594,11 +594,7 @@ mod tests {
594594

595595
repo_utils::become_new_author(&ctx);
596596

597-
ctx.repo
598-
.config()
599-
.unwrap()
600-
.set_str("absorb.forceAuthor", "true")
601-
.unwrap();
597+
repo_utils::set_config_flag(&ctx.repo, "absorb.forceAuthor");
602598

603599
// run 'git-absorb'
604600
let drain = slog::Discard;
@@ -696,6 +692,25 @@ mod tests {
696692
assert!(nothing_left_in_index(&ctx.repo).unwrap());
697693
}
698694

695+
#[test]
696+
fn detached_head_with_force_detach_config() {
697+
let ctx = repo_utils::prepare_and_stage();
698+
repo_utils::detach_head(&ctx);
699+
repo_utils::delete_branch(&ctx.repo, "master");
700+
701+
repo_utils::set_config_flag(&ctx.repo, "absorb.forceDetach");
702+
703+
// run 'git-absorb'
704+
let drain = slog::Discard;
705+
let logger = slog::Logger::root(drain, o!());
706+
run_with_repo(&logger, &DEFAULT_CONFIG, &ctx.repo).unwrap();
707+
let mut revwalk = ctx.repo.revwalk().unwrap();
708+
revwalk.push_head().unwrap();
709+
710+
assert_eq!(revwalk.count(), 3);
711+
assert!(nothing_left_in_index(&ctx.repo).unwrap());
712+
}
713+
699714
#[test]
700715
fn attached_head_pointing_at_commit_on_a_second_branch() {
701716
let ctx = repo_utils::prepare_and_stage();

src/tests/repo_utils.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,8 @@ pub fn delete_branch(repo: &git2::Repository, branch_name: &str) {
104104
.unwrap();
105105
branch.delete().unwrap();
106106
}
107+
108+
/// Set the named repository config flag to true.
109+
pub fn set_config_flag(repo: &git2::Repository, flag_name: &str) {
110+
repo.config().unwrap().set_str(flag_name, "true").unwrap();
111+
}

0 commit comments

Comments
 (0)