Skip to content

Commit b0d70c3

Browse files
committed
Remove force attribute from Config
Avoids the possibility of misusing the flag in lib and below, but now the unit tests do not test the use of the --force flag.
1 parent b24341d commit b0d70c3

File tree

3 files changed

+4
-56
lines changed

3 files changed

+4
-56
lines changed

src/config.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ pub fn unify<'config>(config: &'config Config, repo: &Repository) -> Config<'con
3737
ONE_FIXUP_PER_COMMIT_DEFAULT,
3838
),
3939
force_author: config.force_author
40-
|| config.force
4140
|| bool_value(&repo, FORCE_AUTHOR_CONFIG_NAME, FORCE_AUTHOR_DEFAULT),
4241
force_detach: config.force_detach
43-
|| config.force
4442
|| bool_value(&repo, FORCE_DETACH_CONFIG_NAME, FORCE_DETACH_DEFAULT),
4543
..*config
4644
}

src/lib.rs

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ pub struct Config<'a> {
1313
pub dry_run: bool,
1414
pub force_author: bool,
1515
pub force_detach: bool,
16-
// force should only be used to enable oher force_* values when unifiying the config.
17-
// Do not access when disabling individual safety checks.
18-
pub force: bool,
1916
pub base: Option<&'a str>,
2017
pub and_rebase: bool,
2118
pub whole_file: bool,
@@ -31,8 +28,6 @@ pub fn run(logger: &slog::Logger, config: &Config) -> Result<()> {
3128

3229
fn run_with_repo(logger: &slog::Logger, config: &Config, repo: &git2::Repository) -> Result<()> {
3330
let config = config::unify(&config, repo);
34-
// have force flag enable all force* flags
35-
3631
let stack = stack::working_stack(
3732
repo,
3833
config.base,
@@ -566,28 +561,6 @@ mod tests {
566561
assert!(nothing_left_in_index(&ctx.repo).unwrap());
567562
}
568563

569-
#[test]
570-
fn foreign_author_with_force_flag() {
571-
let ctx = repo_utils::prepare_and_stage();
572-
573-
repo_utils::become_new_author(&ctx.repo);
574-
575-
// run 'git-absorb'
576-
let drain = slog::Discard;
577-
let logger = slog::Logger::root(drain, o!());
578-
let config = Config {
579-
force: true,
580-
..DEFAULT_CONFIG
581-
};
582-
run_with_repo(&logger, &config, &ctx.repo).unwrap();
583-
584-
let mut revwalk = ctx.repo.revwalk().unwrap();
585-
revwalk.push_head().unwrap();
586-
assert_eq!(revwalk.count(), 3);
587-
588-
assert!(nothing_left_in_index(&ctx.repo).unwrap());
589-
}
590-
591564
#[test]
592565
fn foreign_author_with_force_author_config() {
593566
let ctx = repo_utils::prepare_and_stage();
@@ -630,15 +603,15 @@ mod tests {
630603
}
631604

632605
#[test]
633-
fn detached_head_pointing_at_branch_with_force_flag() {
606+
fn detached_head_pointing_at_branch_with_force_detach_flag() {
634607
let ctx = repo_utils::prepare_and_stage();
635608
repo_utils::detach_head(&ctx.repo);
636609

637610
// run 'git-absorb'
638611
let drain = slog::Discard;
639612
let logger = slog::Logger::root(drain, o!());
640613
let config = Config {
641-
force: true,
614+
force_detach: true,
642615
..DEFAULT_CONFIG
643616
};
644617
run_with_repo(&logger, &config, &ctx.repo).unwrap();
@@ -671,27 +644,6 @@ mod tests {
671644
assert!(nothing_left_in_index(&ctx.repo).unwrap());
672645
}
673646

674-
#[test]
675-
fn detached_head_with_force_flag() {
676-
let ctx = repo_utils::prepare_and_stage();
677-
repo_utils::detach_head(&ctx.repo);
678-
repo_utils::delete_branch(&ctx.repo, "master");
679-
680-
// run 'git-absorb'
681-
let drain = slog::Discard;
682-
let logger = slog::Logger::root(drain, o!());
683-
let config = Config {
684-
force: true,
685-
..DEFAULT_CONFIG
686-
};
687-
run_with_repo(&logger, &config, &ctx.repo).unwrap();
688-
let mut revwalk = ctx.repo.revwalk().unwrap();
689-
revwalk.push_head().unwrap();
690-
691-
assert_eq!(revwalk.count(), 3);
692-
assert!(nothing_left_in_index(&ctx.repo).unwrap());
693-
}
694-
695647
#[test]
696648
fn detached_head_with_force_detach_config() {
697649
let ctx = repo_utils::prepare_and_stage();
@@ -834,7 +786,6 @@ mod tests {
834786
dry_run: false,
835787
force_author: false,
836788
force_detach: false,
837-
force: false,
838789
base: None,
839790
and_rebase: false,
840791
whole_file: false,

src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@ fn main() {
9797
&logger,
9898
&git_absorb::Config {
9999
dry_run,
100-
force_author,
101-
force_detach,
102-
force,
100+
force_author: force_author || force,
101+
force_detach: force_detach || force,
103102
base: base.as_deref(),
104103
and_rebase,
105104
whole_file,

0 commit comments

Comments
 (0)