Make FakeGitRepository behave more like a real git repository (#26961)
This PR reworks the `FakeGitRepository` type that we use for testing git interactions, to make it more realistic. In particular, the `status` method now derives the Git status from the differences between HEAD, the index, and the working copy. This way, if you modify a file in the `FakeFs`, the Git repository's `status` method will reflect that modification. Release Notes: - N/A --------- Co-authored-by: Junkui Zhang <364772080@qq.com>
This commit is contained in:
parent
5f398071b2
commit
74a39c7263
15 changed files with 790 additions and 679 deletions
|
@ -1,7 +1,6 @@
|
|||
use crate::status::GitStatus;
|
||||
use crate::SHORT_SHA_LENGTH;
|
||||
use anyhow::{anyhow, Context as _, Result};
|
||||
use askpass::{AskPassResult, AskPassSession};
|
||||
use collections::HashMap;
|
||||
use futures::future::BoxFuture;
|
||||
use futures::{select_biased, AsyncWriteExt, FutureExt as _};
|
||||
|
@ -24,6 +23,8 @@ use sum_tree::MapSeekTarget;
|
|||
use util::command::new_smol_command;
|
||||
use util::ResultExt;
|
||||
|
||||
pub use askpass::{AskPassResult, AskPassSession};
|
||||
|
||||
pub const REMOTE_CANCELLED_BY_USER: &str = "Operation cancelled by user";
|
||||
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
|
||||
|
@ -311,11 +312,13 @@ pub struct RealGitRepository {
|
|||
}
|
||||
|
||||
impl RealGitRepository {
|
||||
pub fn new(repository: git2::Repository, git_binary_path: Option<PathBuf>) -> Self {
|
||||
Self {
|
||||
pub fn new(dotgit_path: &Path, git_binary_path: Option<PathBuf>) -> Option<Self> {
|
||||
let workdir_root = dotgit_path.parent()?;
|
||||
let repository = git2::Repository::open(workdir_root).log_err()?;
|
||||
Some(Self {
|
||||
repository: Arc::new(Mutex::new(repository)),
|
||||
git_binary_path: git_binary_path.unwrap_or_else(|| PathBuf::from("git")),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn working_directory(&self) -> Result<PathBuf> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue