Git push/pull/fetch (#25445)

Release Notes:

- N/A

---------

Co-authored-by: Michael Sloan <mgsloan@gmail.com>
This commit is contained in:
Mikayla Maki 2025-02-24 10:29:52 -08:00 committed by GitHub
parent b1b6401ce7
commit ff6844300e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 1242 additions and 180 deletions

View file

@ -20,7 +20,7 @@ use futures::{
};
use fuzzy::CharBag;
use git::{
repository::{Branch, GitRepository, RepoPath},
repository::{Branch, GitRepository, RepoPath, UpstreamTrackingStatus},
status::{
FileStatus, GitSummary, StatusCode, TrackedStatus, UnmergedStatus, UnmergedStatusCode,
},
@ -202,7 +202,7 @@ pub struct RepositoryEntry {
pub(crate) statuses_by_path: SumTree<StatusEntry>,
work_directory_id: ProjectEntryId,
pub work_directory: WorkDirectory,
pub(crate) branch: Option<Branch>,
pub(crate) current_branch: Option<Branch>,
pub current_merge_conflicts: TreeSet<RepoPath>,
}
@ -216,7 +216,7 @@ impl Deref for RepositoryEntry {
impl RepositoryEntry {
pub fn branch(&self) -> Option<&Branch> {
self.branch.as_ref()
self.current_branch.as_ref()
}
pub fn work_directory_id(&self) -> ProjectEntryId {
@ -244,8 +244,11 @@ impl RepositoryEntry {
pub fn initial_update(&self) -> proto::RepositoryEntry {
proto::RepositoryEntry {
work_directory_id: self.work_directory_id.to_proto(),
branch: self.branch.as_ref().map(|branch| branch.name.to_string()),
branch_summary: self.branch.as_ref().map(branch_to_proto),
branch: self
.current_branch
.as_ref()
.map(|branch| branch.name.to_string()),
branch_summary: self.current_branch.as_ref().map(branch_to_proto),
updated_statuses: self
.statuses_by_path
.iter()
@ -304,8 +307,11 @@ impl RepositoryEntry {
proto::RepositoryEntry {
work_directory_id: self.work_directory_id.to_proto(),
branch: self.branch.as_ref().map(|branch| branch.name.to_string()),
branch_summary: self.branch.as_ref().map(branch_to_proto),
branch: self
.current_branch
.as_ref()
.map(|branch| branch.name.to_string()),
branch_summary: self.current_branch.as_ref().map(branch_to_proto),
updated_statuses,
removed_statuses,
current_merge_conflicts: self
@ -329,7 +335,7 @@ pub fn branch_to_proto(branch: &git::repository::Branch) -> proto::Branch {
ref_name: upstream.ref_name.to_string(),
tracking: upstream
.tracking
.as_ref()
.status()
.map(|upstream| proto::UpstreamTracking {
ahead: upstream.ahead as u64,
behind: upstream.behind as u64,
@ -355,12 +361,16 @@ pub fn proto_to_branch(proto: &proto::Branch) -> git::repository::Branch {
.as_ref()
.map(|upstream| git::repository::Upstream {
ref_name: upstream.ref_name.to_string().into(),
tracking: upstream.tracking.as_ref().map(|tracking| {
git::repository::UpstreamTracking {
ahead: tracking.ahead as u32,
behind: tracking.behind as u32,
}
}),
tracking: upstream
.tracking
.as_ref()
.map(|tracking| {
git::repository::UpstreamTracking::Tracked(UpstreamTrackingStatus {
ahead: tracking.ahead as u32,
behind: tracking.behind as u32,
})
})
.unwrap_or(git::repository::UpstreamTracking::Gone),
}),
most_recent_commit: proto.most_recent_commit.as_ref().map(|commit| {
git::repository::CommitSummary {
@ -2682,7 +2692,8 @@ impl Snapshot {
self.repositories
.update(&PathKey(work_dir_entry.path.clone()), &(), |repo| {
repo.branch = repository.branch_summary.as_ref().map(proto_to_branch);
repo.current_branch =
repository.branch_summary.as_ref().map(proto_to_branch);
repo.statuses_by_path.edit(edits, &());
repo.current_merge_conflicts = conflicted_paths
});
@ -2704,7 +2715,7 @@ impl Snapshot {
work_directory: WorkDirectory::InProject {
relative_path: work_dir_entry.path.clone(),
},
branch: repository.branch_summary.as_ref().map(proto_to_branch),
current_branch: repository.branch_summary.as_ref().map(proto_to_branch),
statuses_by_path: statuses,
current_merge_conflicts: conflicted_paths,
},
@ -3506,7 +3517,7 @@ impl BackgroundScannerState {
RepositoryEntry {
work_directory_id: work_dir_id,
work_directory: work_directory.clone(),
branch: None,
current_branch: None,
statuses_by_path: Default::default(),
current_merge_conflicts: Default::default(),
},
@ -5580,7 +5591,7 @@ fn update_branches(
let mut repository = snapshot
.repository(repository.work_directory.path_key())
.context("Missing repository")?;
repository.branch = branches.into_iter().find(|branch| branch.is_head);
repository.current_branch = branches.into_iter().find(|branch| branch.is_head);
let mut state = state.lock();
state