Rework shared commit editors (#24274)
Rework of https://github.com/zed-industries/zed/pull/24130
Uses
1033c0b57e
`COMMIT_EDITMSG` language-related definitions (thanks @d1y )
Instead of using real `.git/COMMIT_EDITMSG` file, create a buffer
without FS representation, stored in the `Repository` and shared the
regular way via the `BufferStore`.
Adds a knowledge of what `Git Commit` language is, and uses it in the
buffers which are rendered in the git panel.
Release Notes:
- N/A
---------
Co-authored-by: Conrad Irwin <conrad@zed.dev>
Co-authored-by: d1y <chenhonzhou@gmail.com>
Co-authored-by: Smit <smit@zed.dev>
This commit is contained in:
parent
da4bad3a55
commit
868e3f75b2
17 changed files with 428 additions and 372 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::status::FileStatus;
|
||||
use crate::GitHostingProviderRegistry;
|
||||
use crate::{blame::Blame, status::GitStatus};
|
||||
use crate::{GitHostingProviderRegistry, COMMIT_MESSAGE};
|
||||
use anyhow::{anyhow, Context as _, Result};
|
||||
use collections::{HashMap, HashSet};
|
||||
use git2::BranchType;
|
||||
|
@ -68,7 +68,7 @@ pub trait GitRepository: Send + Sync {
|
|||
/// If any of the paths were previously staged but do not exist in HEAD, they will be removed from the index.
|
||||
fn unstage_paths(&self, paths: &[RepoPath]) -> Result<()>;
|
||||
|
||||
fn commit(&self, name_and_email: Option<(&str, &str)>) -> Result<()>;
|
||||
fn commit(&self, message: &str, name_and_email: Option<(&str, &str)>) -> Result<()>;
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for dyn GitRepository {
|
||||
|
@ -298,22 +298,14 @@ impl GitRepository for RealGitRepository {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn commit(&self, name_and_email: Option<(&str, &str)>) -> Result<()> {
|
||||
fn commit(&self, message: &str, name_and_email: Option<(&str, &str)>) -> Result<()> {
|
||||
let working_directory = self
|
||||
.repository
|
||||
.lock()
|
||||
.workdir()
|
||||
.context("failed to read git work directory")?
|
||||
.to_path_buf();
|
||||
let commit_file = self.dot_git_dir().join(*COMMIT_MESSAGE);
|
||||
let commit_file_path = commit_file.to_string_lossy();
|
||||
let mut args = vec![
|
||||
"commit",
|
||||
"--quiet",
|
||||
"-F",
|
||||
commit_file_path.as_ref(),
|
||||
"--cleanup=strip",
|
||||
];
|
||||
let mut args = vec!["commit", "--quiet", "-m", message, "--cleanup=strip"];
|
||||
let author = name_and_email.map(|(name, email)| format!("{name} <{email}>"));
|
||||
if let Some(author) = author.as_deref() {
|
||||
args.push("--author");
|
||||
|
@ -480,7 +472,7 @@ impl GitRepository for FakeGitRepository {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
fn commit(&self, _name_and_email: Option<(&str, &str)>) -> Result<()> {
|
||||
fn commit(&self, _message: &str, _name_and_email: Option<(&str, &str)>) -> Result<()> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue