Add stash apply action

This commit is contained in:
Alvaro Parker 2025-08-19 08:37:59 -04:00
parent 4a11d9d4c6
commit 775425e8c7
No known key found for this signature in database
10 changed files with 180 additions and 6 deletions

View file

@ -60,6 +60,8 @@ actions!(
StashAll,
/// Pops the most recent stash.
StashPop,
/// Apply the most recent stash.
StashApply,
/// Restores all tracked files to their last committed state.
RestoreTrackedFiles,
/// Moves all untracked files to trash.

View file

@ -408,6 +408,12 @@ pub trait GitRepository: Send + Sync {
env: Arc<HashMap<String, String>>,
) -> BoxFuture<'_, Result<()>>;
fn stash_apply(
&self,
index: Option<usize>,
env: Arc<HashMap<String, String>>,
) -> BoxFuture<'_, Result<()>>;
fn stash_drop(
&self,
index: Option<usize>,
@ -1289,6 +1295,35 @@ impl GitRepository for RealGitRepository {
.boxed()
}
fn stash_apply(
&self,
index: Option<usize>,
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");
let mut args = vec!["stash".to_string(), "apply".to_string()];
if let Some(index) = index {
args.push(format!("stash@{{{}}}", index));
}
cmd.current_dir(&working_directory?)
.envs(env.iter())
.args(args);
let output = cmd.output().await?;
anyhow::ensure!(
output.status.success(),
"Failed to apply stash:\n{}",
String::from_utf8_lossy(&output.stderr)
);
Ok(())
})
.boxed()
}
fn stash_drop(
&self,
index: Option<usize>,