git: Amend (#28187)

Adds git amend support.

- [x] Turn existing commit button into split button
- [x] Clean up + Handle shortcuts/focus cases
- [x] Test remote

Release Notes:

- Added git amend support.

---------

Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
Smit Barmase 2025-04-14 21:07:19 +05:30 committed by GitHub
parent ac8a4ba5d4
commit 78ecc3cef0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 595 additions and 84 deletions

View file

@ -50,6 +50,8 @@ actions!(
Pull,
Fetch,
Commit,
Amend,
Cancel,
ExpandCommitEditor,
GenerateCommitMessage,
Init,

View file

@ -74,6 +74,11 @@ impl Upstream {
}
}
#[derive(Clone, Copy, Default)]
pub struct CommitOptions {
pub amend: bool,
}
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
pub enum UpstreamTracking {
/// Remote ref not present in local repository.
@ -252,6 +257,7 @@ pub trait GitRepository: Send + Sync {
&self,
message: SharedString,
name_and_email: Option<(SharedString, SharedString)>,
options: CommitOptions,
env: Arc<HashMap<String, String>>,
) -> BoxFuture<Result<()>>;
@ -368,8 +374,8 @@ impl RealGitRepository {
#[derive(Clone, Debug)]
pub struct GitRepositoryCheckpoint {
ref_name: String,
commit_sha: Oid,
pub ref_name: String,
pub commit_sha: Oid,
}
impl GitRepository for RealGitRepository {
@ -957,6 +963,7 @@ impl GitRepository for RealGitRepository {
&self,
message: SharedString,
name_and_email: Option<(SharedString, SharedString)>,
options: CommitOptions,
env: Arc<HashMap<String, String>>,
) -> BoxFuture<Result<()>> {
let working_directory = self.working_directory();
@ -969,6 +976,10 @@ impl GitRepository for RealGitRepository {
.arg(&message.to_string())
.arg("--cleanup=strip");
if options.amend {
cmd.arg("--amend");
}
if let Some((name, email)) = name_and_email {
cmd.arg("--author").arg(&format!("{name} <{email}>"));
}
@ -1765,6 +1776,7 @@ mod tests {
repo.commit(
"Initial commit".into(),
None,
CommitOptions::default(),
Arc::new(checkpoint_author_envs()),
)
.await
@ -1793,6 +1805,7 @@ mod tests {
repo.commit(
"Commit after checkpoint".into(),
None,
CommitOptions::default(),
Arc::new(checkpoint_author_envs()),
)
.await