Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/ops/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,25 @@ pub(crate) struct CheckoutNewBranch;
impl OpTrait for CheckoutNewBranch {
fn get_action(&self, _target: &ItemData) -> Option<Action> {
Some(Rc::new(|app: &mut App, term: &mut Term| {
let default_start_point = get_current_branch_name(&app.state.repo)?;
let start_point = app.prompt(
term,
&PromptParams {
prompt: "Create and checkout branch starting at:",
create_default_value: Box::new(move |_app| Some(default_start_point.clone())),
..Default::default()
},
)?;

let branch_name = app.prompt(
term,
&PromptParams {
prompt: "Create and checkout branch:",
prompt: "Name for new branch:",
..Default::default()
},
)?;

checkout_new_branch_prompt_update(app, term, &branch_name)?;
checkout_new_branch_prompt_update(app, term, &start_point, &branch_name)?;
Ok(())
}))
}
Expand All @@ -71,9 +81,14 @@ impl OpTrait for CheckoutNewBranch {
}
}

fn checkout_new_branch_prompt_update(app: &mut App, term: &mut Term, branch_name: &str) -> Res<()> {
fn checkout_new_branch_prompt_update(
app: &mut App,
term: &mut Term,
start_point: &str,
branch_name: &str,
) -> Res<()> {
let mut cmd = Command::new("git");
cmd.args(["checkout", "-b", branch_name]);
cmd.args(["checkout", "-b", branch_name, start_point]);

app.close_menu();
app.run_cmd(term, &[], cmd)?;
Expand Down
7 changes: 6 additions & 1 deletion src/tests/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ fn switch_branch_input() {

#[test]
fn checkout_new_branch() {
snapshot!(setup(setup_clone!()), "bcnew<enter>");
snapshot!(setup(setup_clone!()), "bc<enter>new<enter>");
}

#[test]
fn checkout_new_branch_start_point() {
snapshot!(setup(setup_clone!()), "bcunmerged<enter>new<enter>");
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ expression: ctx.redact_buffer()
|
|
────────────────────────────────────────────────────────────────────────────────|
$ git checkout -b new |
$ git checkout -b new main |
Switched to a new branch 'new' |
styles_hash: 2afc72138214b087
styles_hash: 51d00da50a627344
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: src/tests/branch.rs
expression: ctx.redact_buffer()
---
▌On branch new |
|
Recent commits |
c84f226 new unmerged add first commit |
b66a0bf main merged origin/main add initial-file |
|
|
|
|
|
|
|
|
|
|
|
|
────────────────────────────────────────────────────────────────────────────────|
$ git checkout -b new unmerged |
Switched to a new branch 'new' |
styles_hash: 64b6fb8b841715c1