Skip to content
Merged
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
22 changes: 21 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ fn cmd_new(config: &RepoConfig, name: Option<String>, base: &str, print_path: bo
let manager = WorktreeManager::new(config.root.clone())?;
ensure_worktrees_in_gitignore(&config.root, &config.worktree_dir)?;
std::fs::create_dir_all(&config.worktree_dir)?;
let path = manager.create_worktree(&name, base, &config.worktree_dir)?;
let path = manager.create_worktree(&name, base, &config.worktree_dir, |remotes| {
choose_remote_branch(&name, remotes)
})?;

// Pop stash in the new worktree if we migrated changes
if had_changes {
Expand All @@ -208,6 +210,24 @@ fn cmd_new(config: &RepoConfig, name: Option<String>, base: &str, print_path: bo
Ok(())
}

fn choose_remote_branch(name: &str, remotes: &[String]) -> Result<String> {
if remotes.is_empty() {
anyhow::bail!("No remote branches match '{}'.", name);
}

if remotes.len() == 1 {
return Ok(remotes[0].clone());
}

let selection = Select::new()
.with_prompt(format!("Select remote branch for '{}'", name))
.items(remotes)
.default(0)
.interact()?;

Ok(remotes[selection].clone())
}

fn migrate_from_current_branch(repo_path: &Path, root_branch: &str) -> Result<bool> {
// Check for uncommitted changes
let status = Command::new("git")
Expand Down
22 changes: 21 additions & 1 deletion src/session_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,31 @@ fn ensure_worktree_path(
}
None => {
eprintln!("Creating worktree: {}", name);
manager.create_worktree(name, base, &context.repo.worktree_dir)
manager.create_worktree(name, base, &context.repo.worktree_dir, |remotes| {
choose_remote_branch(name, remotes)
})
}
}
}

fn choose_remote_branch(name: &str, remotes: &[String]) -> Result<String> {
if remotes.is_empty() {
anyhow::bail!("No remote branches match '{}'.", name);
}

if remotes.len() == 1 {
return Ok(remotes[0].clone());
}

let selection = Select::new()
.with_prompt(format!("Select remote branch for '{}'", name))
.items(remotes)
.default(0)
.interact()?;

Ok(remotes[selection].clone())
}

fn panes_tmux() -> TmuxManager {
TmuxManager::new(SESSION_NAME)
}
Expand Down
Loading
Loading