git: Enable git stash in git panel (#32821)
Related discussion #31484 Release Notes: - Added a menu entry on the git panel to git stash and git pop stash. Preview:  --------- Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
parent
4d00d07df1
commit
07252c3309
10 changed files with 290 additions and 2 deletions
|
@ -55,6 +55,10 @@ actions!(
|
|||
StageAll,
|
||||
/// Unstages all changes in the repository.
|
||||
UnstageAll,
|
||||
/// Stashes all changes in the repository, including untracked files.
|
||||
StashAll,
|
||||
/// Pops the most recent stash.
|
||||
StashPop,
|
||||
/// Restores all tracked files to their last committed state.
|
||||
RestoreTrackedFiles,
|
||||
/// Moves all untracked files to trash.
|
||||
|
|
|
@ -395,6 +395,14 @@ pub trait GitRepository: Send + Sync {
|
|||
env: Arc<HashMap<String, String>>,
|
||||
) -> BoxFuture<'_, Result<()>>;
|
||||
|
||||
fn stash_paths(
|
||||
&self,
|
||||
paths: Vec<RepoPath>,
|
||||
env: Arc<HashMap<String, String>>,
|
||||
) -> BoxFuture<Result<()>>;
|
||||
|
||||
fn stash_pop(&self, env: Arc<HashMap<String, String>>) -> BoxFuture<Result<()>>;
|
||||
|
||||
fn push(
|
||||
&self,
|
||||
branch_name: String,
|
||||
|
@ -1189,6 +1197,55 @@ impl GitRepository for RealGitRepository {
|
|||
.boxed()
|
||||
}
|
||||
|
||||
fn stash_paths(
|
||||
&self,
|
||||
paths: Vec<RepoPath>,
|
||||
env: Arc<HashMap<String, String>>,
|
||||
) -> BoxFuture<Result<()>> {
|
||||
let working_directory = self.working_directory();
|
||||
self.executor
|
||||
.spawn(async move {
|
||||
let mut cmd = new_smol_command("git");
|
||||
cmd.current_dir(&working_directory?)
|
||||
.envs(env.iter())
|
||||
.args(["stash", "push", "--quiet"])
|
||||
.arg("--include-untracked");
|
||||
|
||||
cmd.args(paths.iter().map(|p| p.as_ref()));
|
||||
|
||||
let output = cmd.output().await?;
|
||||
|
||||
anyhow::ensure!(
|
||||
output.status.success(),
|
||||
"Failed to stash:\n{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
Ok(())
|
||||
})
|
||||
.boxed()
|
||||
}
|
||||
|
||||
fn stash_pop(&self, env: Arc<HashMap<String, String>>) -> BoxFuture<Result<()>> {
|
||||
let working_directory = self.working_directory();
|
||||
self.executor
|
||||
.spawn(async move {
|
||||
let mut cmd = new_smol_command("git");
|
||||
cmd.current_dir(&working_directory?)
|
||||
.envs(env.iter())
|
||||
.args(["stash", "pop"]);
|
||||
|
||||
let output = cmd.output().await?;
|
||||
|
||||
anyhow::ensure!(
|
||||
output.status.success(),
|
||||
"Failed to stash pop:\n{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
Ok(())
|
||||
})
|
||||
.boxed()
|
||||
}
|
||||
|
||||
fn commit(
|
||||
&self,
|
||||
message: SharedString,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue