Skip to content

Commit

Permalink
feat(hide): remove -D option from git hide
Browse files Browse the repository at this point in the history
  • Loading branch information
arxanas committed Dec 23, 2023
1 parent f8c2b0d commit 1841ded
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 55 deletions.
2 changes: 1 addition & 1 deletion git-branchless-lib/tests/test_eventlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn test_different_event_transaction_ids() -> eyre::Result<()> {

git.init_repo()?;
git.commit_file("test1", 1)?;
git.branchless("hide", &["HEAD"])?;
git.branchless("hide", &["--no-delete-branches", "HEAD"])?;

let repo = git.get_repo()?;
let conn = repo.get_db_conn()?;
Expand Down
7 changes: 4 additions & 3 deletions git-branchless-opts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,10 @@ pub enum Command {
#[clap(flatten)]
resolve_revset_options: ResolveRevsetOptions,

/// Also delete any branches that are abandoned as a result of this hide.
#[clap(action, short = 'D', long = "delete-branches")]
delete_branches: bool,
/// Don't delete branches that point to commits that would be hidden.
/// (Those commits will remain visible as a result.)
#[clap(action, long = "no-delete-branches")]
no_delete_branches: bool,

/// Also recursively hide all visible children commits of the provided
/// commits.
Expand Down
2 changes: 1 addition & 1 deletion git-branchless-query/tests/test_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn test_query_hidden_commits() -> eyre::Result<()> {
let test2_oid = git.commit_file("test2", 2)?;
git.commit_file("test3", 3)?;

git.branchless("hide", &["HEAD"])?;
git.branchless("hide", &["--no-delete-branches", "HEAD"])?;
git.run(&["checkout", &test2_oid.to_string()])?;

{
Expand Down
12 changes: 7 additions & 5 deletions git-branchless/src/commands/hide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn hide(
git_run_info: &GitRunInfo,
revsets: Vec<Revset>,
resolve_revset_options: &ResolveRevsetOptions,
delete_branches: bool,
no_delete_branches: bool,
recursive: bool,
) -> EyreExitOr<()> {
let now = SystemTime::now();
Expand All @@ -44,6 +44,7 @@ pub fn hide(
event_cursor,
&references_snapshot,
)?;
let delete_branches = !no_delete_branches;

let commit_sets =
match resolve_commits(effects, &repo, &mut dag, &revsets, resolve_revset_options) {
Expand Down Expand Up @@ -155,16 +156,17 @@ pub fn hide(
// This message will look like either of these:
// To unhide these X commits, run: git undo
// To unhide these X commits and restore X branches, run: git undo
let delete_branches_message = match delete_branches {
true => format!(
let delete_branches_message = if delete_branches && !abandoned_branches.is_empty() {
format!(
" and restore {}",
Pluralize {
determiner: None,
amount: abandoned_branches.len(),
unit: ("branch", "branches"),
}
),
false => String::new(),
)
} else {
String::new()
};
writeln!(
effects.get_output_stream(),
Expand Down
4 changes: 2 additions & 2 deletions git-branchless/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ fn command_main(ctx: CommandContext, opts: Opts) -> EyreExitOr<()> {
Command::Hide {
revsets,
resolve_revset_options,
delete_branches,
no_delete_branches,
recursive,
} => hide::hide(
&effects,
&git_run_info,
revsets,
&resolve_revset_options,
delete_branches,
no_delete_branches,
recursive,
)?,

Expand Down
28 changes: 17 additions & 11 deletions git-branchless/tests/test_branchless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,54 @@ fn test_commands() -> eyre::Result<()> {

git.init_repo()?;
git.commit_file("test", 1)?;
git.detach_head()?;
git.commit_file("test2", 2)?;

{
let stdout = git.smartlog()?;
insta::assert_snapshot!(stdout, @r###"
:
@ 3df4b93 (> master) create test.txt
O 3df4b93 (master) create test.txt
|
@ 73b746c create test2.txt
"###);
}

{
let (stdout, _stderr) = git.branchless("hide", &["3df4b935"])?;
let (stdout, _stderr) = git.branchless("hide", &["HEAD"])?;
insta::assert_snapshot!(stdout, @r###"
Hid commit: 3df4b93 create test.txt
Abandoned 1 branch: master
Hid commit: 73b746c create test2.txt
To unhide this 1 commit, run: git undo
"###);
}

{
let (stdout, _stderr) = git.branchless("unhide", &["3df4b935"])?;
let (stdout, _stderr) = git.branchless("unhide", &["HEAD"])?;
insta::assert_snapshot!(stdout, @r###"
Unhid commit: 3df4b93 create test.txt
Unhid commit: 73b746c create test2.txt
To hide this 1 commit, run: git undo
"###);
}

{
let (stdout, _stderr) = git.branchless("prev", &[])?;
insta::assert_snapshot!(stdout, @r###"
branchless: running command: <git-executable> checkout f777ecc9b0db5ed372b2615695191a8a17f79f24
@ f777ecc create initial.txt
branchless: running command: <git-executable> checkout master
:
@ 3df4b93 (> master) create test.txt
|
O 3df4b93 (master) create test.txt
o 73b746c create test2.txt
"###);
}

{
let (stdout, _stderr) = git.branchless("next", &[])?;
insta::assert_snapshot!(stdout, @r###"
branchless: running command: <git-executable> checkout master
branchless: running command: <git-executable> checkout 73b746ca864a21fc0c3dedbc937eaa9e279b73eb
:
@ 3df4b93 (> master) create test.txt
O 3df4b93 (master) create test.txt
|
@ 73b746c create test2.txt
"###);
}

Expand Down
3 changes: 1 addition & 2 deletions git-branchless/tests/test_eventlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ fn test_git_v2_31_events() -> eyre::Result<()> {
git.run(&["checkout", "HEAD^"])?;
git.commit_file("test2", 2)?;
git.branchless("hide", &["test1"])?;
git.run(&["branch", "-D", "test1"])?;

let effects = Effects::new_suppress_for_test(Glyphs::text());
let repo = git.get_repo()?;
Expand Down Expand Up @@ -140,7 +139,7 @@ fn test_git_v2_31_events() -> eyre::Result<()> {
RefUpdateEvent {
timestamp: 0.0,
event_tx_id: Id(
10,
9,
),
ref_name: ReferenceName(
"refs/heads/test1",
Expand Down
18 changes: 6 additions & 12 deletions git-branchless/tests/test_hide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn test_branches_always_visible() -> eyre::Result<()> {
git.run(&["branch", "test"])?;
git.run(&["checkout", "master"])?;

let (stdout, _stderr) = git.branchless("hide", &["test", "test^"])?;
let (stdout, _stderr) = git.branchless("hide", &["--no-delete-branches", "test", "test^"])?;
insta::assert_snapshot!(stdout, @r###"
Hid commit: 62fc20d create test1.txt
Hid commit: 96d1c37 create test2.txt
Expand Down Expand Up @@ -213,7 +213,7 @@ fn test_hide_delete_branches() -> eyre::Result<()> {
git.run(&["branch", "test"])?;
git.run(&["checkout", "master"])?;

let (stdout, _stderr) = git.branchless("hide", &["--delete-branches", "test", "test^"])?;
let (stdout, _stderr) = git.branchless("hide", &["test", "test^"])?;
insta::assert_snapshot!(stdout, @r###"
Hid commit: 62fc20d create test1.txt
Hid commit: 96d1c37 create test2.txt
Expand Down Expand Up @@ -278,14 +278,8 @@ fn test_hide_delete_multiple_branches() -> eyre::Result<()> {
"###);
}

let (stdout, _stderr) = git.branchless(
"hide",
&[
"--delete-branches",
&test1_oid.to_string(),
&test2_oid.to_string(),
],
)?;
let (stdout, _stderr) =
git.branchless("hide", &[&test1_oid.to_string(), &test2_oid.to_string()])?;
insta::assert_snapshot!(stdout, @r###"
Hid commit: 62fc20d create test1.txt
Hid commit: fe65c1f create test2.txt
Expand Down Expand Up @@ -313,7 +307,7 @@ fn test_hide_delete_checked_out_branch() -> eyre::Result<()> {
git.commit_file("test1", 1)?;
git.commit_file("test2", 2)?;

let (stdout, _stderr) = git.branchless("hide", &["--delete-branches", "test"])?;
let (stdout, _stderr) = git.branchless("hide", &["test"])?;
insta::assert_snapshot!(stdout, @r###"
Hid commit: 96d1c37 create test2.txt
branchless: processing 1 update: branch test
Expand Down Expand Up @@ -551,7 +545,7 @@ fn test_smartlog_show_only_branches() -> eyre::Result<()> {

git.run(&["branch", "branch-2", &test2_oid.to_string()])?;
git.run(&["branch", "branch-4", &test4_oid.to_string()])?;
git.branchless("hide", &[&test4_oid.to_string()])?;
git.branchless("hide", &["--no-delete-branches", &test4_oid.to_string()])?;
git.branchless("hide", &[&test6_oid.to_string()])?;

// confirm our baseline:
Expand Down
Loading

0 comments on commit 1841ded

Please sign in to comment.