git: Add option to branch from default branch in branch picker (#34663)
Closes #33700 The option shows up as an icon that appears on entries that would create a new branch. You can also branch from the default by secondary confirming, which the icon has a tooltip for as well. We based the default branch on the results from this command: `git symbolic-ref refs/remotes/upstream/HEAD` and fallback to `git symbolic-ref refs/remotes/origin/HEAD` Release Notes: - Add option to create a branch from a default branch in git branch picker --------- Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
parent
fa8dd1c547
commit
9fa634f02f
7 changed files with 133 additions and 9 deletions
|
@ -463,6 +463,8 @@ pub trait GitRepository: Send + Sync {
|
|||
base_checkpoint: GitRepositoryCheckpoint,
|
||||
target_checkpoint: GitRepositoryCheckpoint,
|
||||
) -> BoxFuture<'_, Result<String>>;
|
||||
|
||||
fn default_branch(&self) -> BoxFuture<'_, Result<Option<SharedString>>>;
|
||||
}
|
||||
|
||||
pub enum DiffType {
|
||||
|
@ -1607,6 +1609,37 @@ impl GitRepository for RealGitRepository {
|
|||
})
|
||||
.boxed()
|
||||
}
|
||||
|
||||
fn default_branch(&self) -> BoxFuture<'_, Result<Option<SharedString>>> {
|
||||
let working_directory = self.working_directory();
|
||||
let git_binary_path = self.git_binary_path.clone();
|
||||
|
||||
let executor = self.executor.clone();
|
||||
self.executor
|
||||
.spawn(async move {
|
||||
let working_directory = working_directory?;
|
||||
let git = GitBinary::new(git_binary_path, working_directory, executor);
|
||||
|
||||
if let Ok(output) = git
|
||||
.run(&["symbolic-ref", "refs/remotes/upstream/HEAD"])
|
||||
.await
|
||||
{
|
||||
let output = output
|
||||
.strip_prefix("refs/remotes/upstream/")
|
||||
.map(|s| SharedString::from(s.to_owned()));
|
||||
return Ok(output);
|
||||
}
|
||||
|
||||
let output = git
|
||||
.run(&["symbolic-ref", "refs/remotes/origin/HEAD"])
|
||||
.await?;
|
||||
|
||||
Ok(output
|
||||
.strip_prefix("refs/remotes/origin/")
|
||||
.map(|s| SharedString::from(s.to_owned())))
|
||||
})
|
||||
.boxed()
|
||||
}
|
||||
}
|
||||
|
||||
fn git_status_args(path_prefixes: &[RepoPath]) -> Vec<OsString> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue