Skip to content

Commit 1bcd755

Browse files
committed
Revert "Add support for interactively checking out a branch"
This reverts commit 7ce51cc. Temporarily reverting this commit in order to release a fix for #581.
1 parent 7ce51cc commit 1bcd755

8 files changed

Lines changed: 29 additions & 160 deletions

File tree

flake.nix

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
checkFlags = [
6060
"--skip=test_checkout_pty"
6161
"--skip=test_next_ambiguous_interactive"
62-
"--skip=test_checkout_auto_switch_interactive"
63-
"--skip=test_checkout_auto_switch_interactive_disabled"
6462
];
6563
}
6664
)

git-branchless-lib/src/core/check_out.rs

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ use std::time::{SystemTime, UNIX_EPOCH};
77
use cursive::theme::BaseColor;
88
use cursive::utils::markup::StyledString;
99
use eyre::Context;
10-
use itertools::Itertools;
1110
use tracing::instrument;
1211

13-
use crate::core::config::get_auto_switch_branches;
1412
use crate::git::{
1513
update_index, CategorizedReferenceName, GitRunInfo, MaybeZeroOid, NonZeroOid, ReferenceName,
1614
Repo, Stage, UpdateIndexCommand, WorkingCopySnapshot,
@@ -21,7 +19,6 @@ use super::config::get_undo_create_snapshots;
2119
use super::effects::Effects;
2220
use super::eventlog::{Event, EventLogDb, EventTransactionId};
2321
use super::formatting::printable_styled_string;
24-
use super::repo_ext::{RepoExt, RepoReferencesSnapshot};
2522

2623
/// An entity to check out.
2724
#[derive(Clone, Debug)]
@@ -57,40 +54,6 @@ impl Default for CheckOutCommitOptions {
5754
}
5855
}
5956

60-
fn maybe_get_branch_name(
61-
current_target: Option<String>,
62-
oid: Option<NonZeroOid>,
63-
repo: &Repo,
64-
) -> eyre::Result<Option<String>> {
65-
let RepoReferencesSnapshot {
66-
head_oid,
67-
branch_oid_to_names,
68-
..
69-
} = repo.get_references_snapshot()?;
70-
if (head_oid.is_some() && head_oid == oid) || current_target == head_oid.map(|o| o.to_string())
71-
{
72-
// Don't try to checkout the branch if we aren't actually checking anything new out.
73-
return Ok(current_target);
74-
}
75-
76-
// Determine if the oid corresponds to exactly a single branch. If so,
77-
// check that out directly.
78-
match oid {
79-
Some(oid) => match branch_oid_to_names.get(&oid) {
80-
Some(branch_names) => match branch_names.iter().exactly_one() {
81-
Ok(branch_name) => {
82-
// To remove the `refs/heads/` prefix
83-
let name = CategorizedReferenceName::new(branch_name);
84-
Ok(Some(name.remove_prefix()?))
85-
}
86-
Err(_) => Ok(current_target),
87-
},
88-
None => Ok(current_target),
89-
},
90-
None => Ok(current_target),
91-
}
92-
}
93-
9457
/// Checks out the requested commit. If the operation succeeds, then displays
9558
/// the new smartlog. Otherwise displays a warning message.
9659
#[instrument]
@@ -108,25 +71,20 @@ pub fn check_out_commit(
10871
render_smartlog,
10972
} = options;
11073

111-
let (target, oid) = match target {
112-
None => (None, None),
74+
let target = match target {
75+
None => None,
11376
Some(CheckoutTarget::Reference(reference_name)) => {
11477
let categorized_target = CategorizedReferenceName::new(&reference_name);
115-
(Some(categorized_target.remove_prefix()?), None)
78+
Some(categorized_target.remove_prefix()?)
11679
}
117-
Some(CheckoutTarget::Oid(oid)) => (Some(oid.to_string()), Some(oid)),
118-
Some(CheckoutTarget::Unknown(target)) => (Some(target), None),
80+
Some(CheckoutTarget::Oid(oid)) => Some(oid.to_string()),
81+
Some(CheckoutTarget::Unknown(target)) => Some(target),
11982
};
12083

12184
if get_undo_create_snapshots(repo)? {
12285
create_snapshot(effects, git_run_info, repo, event_log_db, event_tx_id)?;
12386
}
12487

125-
let target = if get_auto_switch_branches(repo)? {
126-
maybe_get_branch_name(target, oid, repo)?
127-
} else {
128-
target
129-
};
13088
let args = {
13189
let mut args = vec![OsStr::new("checkout")];
13290
if let Some(target) = &target {

git-branchless-lib/src/core/config.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,6 @@ pub fn get_main_branch_name(repo: &Repo) -> eyre::Result<String> {
4545
Ok("master".to_string())
4646
}
4747

48-
/// If `true`, switch to the branch associated with a target commit instead of
49-
/// the commit directly.
50-
///
51-
/// The switch will only occur if it is the only branch on the target commit.
52-
#[instrument]
53-
pub fn get_auto_switch_branches(repo: &Repo) -> eyre::Result<bool> {
54-
repo.get_readonly_config()?
55-
.get_or("branchless.navigation.autoSwitchBranches", true)
56-
}
57-
5848
/// Get the default comment character.
5949
#[instrument]
6050
pub fn get_comment_char(repo: &Repo) -> eyre::Result<char> {

git-branchless/tests/command/test_move.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3066,7 +3066,8 @@ fn test_move_branches_after_move() -> eyre::Result<()> {
30663066
insta::assert_snapshot!(stderr, @r###"
30673067
branchless: creating working copy snapshot
30683068
Previous HEAD position was f81d55c create test5.txt
3069-
Switched to branch 'bar'
3069+
branchless: processing 1 update: ref HEAD
3070+
HEAD is now at 566e434 create test5.txt
30703071
branchless: processing checkout
30713072
"###);
30723073
insta::assert_snapshot!(stdout, @r###"
@@ -3076,15 +3077,15 @@ fn test_move_branches_after_move() -> eyre::Result<()> {
30763077
[3/3] Committed as: 566e434 create test5.txt
30773078
branchless: processing 2 updates: branch bar, branch foo
30783079
branchless: processing 3 rewritten commits
3079-
branchless: running command: <git-executable> checkout bar
3080+
branchless: running command: <git-executable> checkout 566e4341a4a9a930fc2bf7ccdfa168e9f266c34a
30803081
:
30813082
O 62fc20d create test1.txt
30823083
|\
30833084
| o 4838e49 (foo) create test3.txt
30843085
| |
30853086
| o a248207 create test4.txt
30863087
| |
3087-
| @ 566e434 (> bar) create test5.txt
3088+
| @ 566e434 (bar) create test5.txt
30883089
|
30893090
O 96d1c37 (master) create test2.txt
30903091
In-memory rebase succeeded.
@@ -3101,7 +3102,7 @@ fn test_move_branches_after_move() -> eyre::Result<()> {
31013102
| |
31023103
| o a248207 create test4.txt
31033104
| |
3104-
| @ 566e434 (> bar) create test5.txt
3105+
| @ 566e434 (bar) create test5.txt
31053106
|
31063107
O 96d1c37 (master) create test2.txt
31073108
"###);
@@ -3120,7 +3121,7 @@ fn test_move_branches_after_move() -> eyre::Result<()> {
31203121
| |
31213122
| o a248207 create test4.txt
31223123
| |
3123-
| @ 566e434 (> bar) create test5.txt
3124+
| @ 566e434 (bar) create test5.txt
31243125
|
31253126
O 96d1c37 (master) create test2.txt
31263127
"###);
@@ -3426,12 +3427,13 @@ fn test_move_delete_checked_out_branch() -> eyre::Result<()> {
34263427
branchless: processing 3 rewritten commits
34273428
branchless: processing 2 updates: branch more-work, branch work
34283429
branchless: creating working copy snapshot
3429-
branchless: running command: <git-executable> checkout master
3430+
branchless: running command: <git-executable> checkout 91c5ce63686889388daec1120bf57bea8a744bc2
34303431
Previous HEAD position was 012efd6 create test3.txt
3431-
Switched to branch 'master'
3432+
branchless: processing 1 update: ref HEAD
3433+
HEAD is now at 91c5ce6 create test2.txt
34323434
branchless: processing checkout
34333435
:
3434-
@ 91c5ce6 (> master) create test2.txt
3436+
@ 91c5ce6 (master) create test2.txt
34353437
|
34363438
o 012efd6 (more-work) create test3.txt
34373439
Successfully rebased and updated detached HEAD.
@@ -3449,7 +3451,7 @@ fn test_move_delete_checked_out_branch() -> eyre::Result<()> {
34493451
let (stdout, _stderr) = git.run(&["smartlog"])?;
34503452
insta::assert_snapshot!(stdout, @r###"
34513453
:
3452-
@ 91c5ce6 (> master) create test2.txt
3454+
@ 91c5ce6 (master) create test2.txt
34533455
|
34543456
o 012efd6 (more-work) create test3.txt
34553457
"###);
@@ -3464,7 +3466,8 @@ fn test_move_delete_checked_out_branch() -> eyre::Result<()> {
34643466
insta::assert_snapshot!(stderr, @r###"
34653467
branchless: creating working copy snapshot
34663468
Previous HEAD position was 96d1c37 create test2.txt
3467-
Switched to branch 'master'
3469+
branchless: processing 1 update: ref HEAD
3470+
HEAD is now at 91c5ce6 create test2.txt
34683471
branchless: processing checkout
34693472
"###);
34703473
insta::assert_snapshot!(stdout, @r###"
@@ -3474,9 +3477,9 @@ fn test_move_delete_checked_out_branch() -> eyre::Result<()> {
34743477
[3/3] Committed as: 012efd6 create test3.txt
34753478
branchless: processing 2 updates: branch more-work, branch work
34763479
branchless: processing 3 rewritten commits
3477-
branchless: running command: <git-executable> checkout master
3480+
branchless: running command: <git-executable> checkout 91c5ce63686889388daec1120bf57bea8a744bc2
34783481
:
3479-
@ 91c5ce6 (> master) create test2.txt
3482+
@ 91c5ce6 (master) create test2.txt
34803483
|
34813484
o 012efd6 (more-work) create test3.txt
34823485
In-memory rebase succeeded.
@@ -3487,7 +3490,7 @@ fn test_move_delete_checked_out_branch() -> eyre::Result<()> {
34873490
let (stdout, _stderr) = git.run(&["smartlog"])?;
34883491
insta::assert_snapshot!(stdout, @r###"
34893492
:
3490-
@ 91c5ce6 (> master) create test2.txt
3493+
@ 91c5ce6 (master) create test2.txt
34913494
|
34923495
o 012efd6 (more-work) create test3.txt
34933496
"###);

git-branchless/tests/command/test_navigation.rs

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ fn test_checkout_pty_branch() -> eyre::Result<()> {
600600
let (stdout, _stderr) = git.run(&["smartlog"])?;
601601
insta::assert_snapshot!(stdout, @r###"
602602
:
603-
@ 62fc20d (> master) create test1.txt
603+
@ 62fc20d (master) create test1.txt
604604
|\
605605
| o 96d1c37 create test2.txt
606606
|
@@ -839,83 +839,3 @@ fn test_navigation_checkout_target_only() -> eyre::Result<()> {
839839

840840
Ok(())
841841
}
842-
843-
#[test]
844-
#[cfg(unix)]
845-
fn test_checkout_auto_switch_interactive() -> eyre::Result<()> {
846-
let git = make_git()?;
847-
848-
git.init_repo()?;
849-
git.detach_head()?;
850-
git.commit_file("test1", 1)?;
851-
git.run(&["branch", "test1"])?;
852-
git.commit_file("test2", 2)?;
853-
git.run(&["branch", "test2"])?;
854-
855-
run_in_pty(
856-
&git,
857-
&["co", "--interactive"],
858-
&[
859-
PtyAction::WaitUntilContains("> "),
860-
PtyAction::Write("test1"),
861-
PtyAction::WaitUntilContains("> 62fc20d"),
862-
PtyAction::Write(CARRIAGE_RETURN),
863-
],
864-
)?;
865-
866-
{
867-
let (stdout, _stderr) = git.run(&["smartlog"])?;
868-
insta::assert_snapshot!(stdout, @r###"
869-
O f777ecc (master) create initial.txt
870-
|
871-
@ 62fc20d (> test1) create test1.txt
872-
|
873-
o 96d1c37 (test2) create test2.txt
874-
"###);
875-
}
876-
877-
return Ok(());
878-
}
879-
880-
#[test]
881-
#[cfg(unix)]
882-
fn test_checkout_auto_switch_interactive_disabled() -> eyre::Result<()> {
883-
let git = make_git()?;
884-
885-
git.init_repo()?;
886-
git.run(&[
887-
"config",
888-
"branchless.navigation.autoSwitchBranches",
889-
"false",
890-
])?;
891-
892-
git.detach_head()?;
893-
git.commit_file("test1", 1)?;
894-
git.run(&["branch", "test1"])?;
895-
git.commit_file("test2", 2)?;
896-
git.run(&["branch", "test2"])?;
897-
898-
run_in_pty(
899-
&git,
900-
&["co", "--interactive"],
901-
&[
902-
PtyAction::WaitUntilContains("> "),
903-
PtyAction::Write("test1"),
904-
PtyAction::WaitUntilContains("> 62fc20d"),
905-
PtyAction::Write(CARRIAGE_RETURN),
906-
],
907-
)?;
908-
909-
{
910-
let (stdout, _stderr) = git.run(&["smartlog"])?;
911-
insta::assert_snapshot!(stdout, @r###"
912-
O f777ecc (master) create initial.txt
913-
|
914-
@ 62fc20d (test1) create test1.txt
915-
|
916-
o 96d1c37 (test2) create test2.txt
917-
"###);
918-
}
919-
920-
return Ok(());
921-
}

git-branchless/tests/command/test_reword.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn test_reword_current_commit_not_head() -> eyre::Result<()> {
4949
let (stdout, _stderr) = git.run(&["smartlog"])?;
5050
insta::assert_snapshot!(stdout, @r###"
5151
:
52-
@ 62fc20d (> test1) create test1.txt
52+
@ 62fc20d (test1) create test1.txt
5353
|
5454
O 96d1c37 (master) create test2.txt
5555
"###);
@@ -59,7 +59,7 @@ fn test_reword_current_commit_not_head() -> eyre::Result<()> {
5959
let (stdout, _stderr) = git.run(&["smartlog"])?;
6060
insta::assert_snapshot!(stdout, @r###"
6161
:
62-
@ a6f8868 (> test1) foo
62+
@ a6f8868 (test1) foo
6363
|
6464
O 5207ad5 (master) create test2.txt
6565
"###);

git-branchless/tests/command/test_undo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ fn test_undo_move_refs() -> eyre::Result<()> {
412412
to 62fc20d create test1.txt
413413
3. Check out from 96d1c37 create test2.txt
414414
to 62fc20d create test1.txt
415-
Confirm? [yN] branchless: running command: <git-executable> checkout master --detach
415+
Confirm? [yN] branchless: running command: <git-executable> checkout 62fc20d2a290daea0d52bdc2ed2ad4be6491010e --detach
416416
Applied 3 inverse events.
417417
"###);
418418
assert_eq!(exit_code, 0);
@@ -637,7 +637,7 @@ fn test_undo_doesnt_make_working_dir_dirty() -> eyre::Result<()> {
637637
to f777ecc create initial.txt
638638
5. Delete branch foo at f777ecc create initial.txt
639639
640-
Confirm? [yN] branchless: running command: <git-executable> checkout master --detach
640+
Confirm? [yN] branchless: running command: <git-executable> checkout f777ecc9b0db5ed372b2615695191a8a17f79f24 --detach
641641
Applied 5 inverse events.
642642
"###);
643643
assert_eq!(exit_code, 0);
@@ -876,7 +876,7 @@ fn test_undo_noninteractive() -> eyre::Result<()> {
876876
to 96d1c37 create test2.txt
877877
4. Check out from 9ed8f9a bad message
878878
to 96d1c37 create test2.txt
879-
Confirm? [yN] branchless: running command: <git-executable> checkout master --detach
879+
Confirm? [yN] branchless: running command: <git-executable> checkout 96d1c37a3d4363611c49f7e52186e189a04c531f --detach
880880
:
881881
@ 96d1c37 (master) create test2.txt
882882
Applied 4 inverse events.

git-branchless/tests/test_branchless.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ fn test_commands() -> eyre::Result<()> {
4848
{
4949
let (stdout, _stderr) = git.run(&["next"])?;
5050
insta::assert_snapshot!(stdout, @r###"
51-
branchless: running command: <git-executable> checkout master
51+
branchless: running command: <git-executable> checkout 3df4b9355b3b072aa6c50c6249bf32e289b3a661
5252
:
53-
@ 3df4b93 (> master) create test.txt
53+
@ 3df4b93 (master) create test.txt
5454
"###);
5555
}
5656

0 commit comments

Comments
 (0)