Skip to content

Commit

Permalink
support pull from remote (#945)
Browse files Browse the repository at this point in the history
closes #920
  • Loading branch information
R0nd authored Oct 13, 2021
1 parent 31f6771 commit 153c79a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Added
- add `trace-libgit` feature to make git tracing optional [[@dm9pZCAq](https://github.com/dm9pZCAq)] ([#902](https://github.com/extrawurst/gitui/issues/902))
- support merging and rebasing remote branches ([#920](https://github.com/extrawurst/gitui/issues/920))

## [0.18] - 2021-10-11

Expand Down
13 changes: 9 additions & 4 deletions asyncgit/src/sync/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ pub fn abort_merge(repo_path: &str) -> Result<()> {
}

///
pub fn merge_branch(repo_path: &str, branch: &str) -> Result<()> {
pub fn merge_branch(
repo_path: &str,
branch: &str,
branch_type: BranchType,
) -> Result<()> {
scope_time!("merge_branch");

let repo = utils::repo(repo_path)?;

merge_branch_repo(&repo, branch)?;
merge_branch_repo(&repo, branch, branch_type)?;

Ok(())
}
Expand Down Expand Up @@ -89,8 +93,9 @@ pub fn abort_pending_rebase(repo_path: &str) -> Result<()> {
pub fn merge_branch_repo(
repo: &Repository,
branch: &str,
branch_type: BranchType,
) -> Result<()> {
let branch = repo.find_branch(branch, BranchType::Local)?;
let branch = repo.find_branch(branch, branch_type)?;

let annotated =
repo.reference_to_annotated_commit(&branch.into_reference())?;
Expand Down Expand Up @@ -162,7 +167,7 @@ mod tests {

write_commit_file(&repo, "test.txt", "test2", "commit2");

merge_branch(repo_path, "master").unwrap();
merge_branch(repo_path, "master", BranchType::Local).unwrap();

let msg = merge_msg(repo_path).unwrap();

Expand Down
1 change: 1 addition & 0 deletions asyncgit/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub use config::{
ShowUntrackedFilesConfig,
};
pub use diff::get_diff_commit;
pub use git2::BranchType;
pub use hooks::{
hooks_commit_msg, hooks_post_commit, hooks_pre_commit, HookResult,
};
Expand Down
13 changes: 9 additions & 4 deletions asyncgit/src/sync/rebase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ use super::CommitId;
pub fn rebase_branch(
repo_path: &str,
branch: &str,
branch_type: BranchType,
) -> Result<RebaseState> {
scope_time!("rebase_branch");

let repo = utils::repo(repo_path)?;

rebase_branch_repo(&repo, branch)
rebase_branch_repo(&repo, branch, branch_type)
}

fn rebase_branch_repo(
repo: &Repository,
branch_name: &str,
branch_type: BranchType,
) -> Result<RebaseState> {
let branch = repo.find_branch(branch_name, BranchType::Local)?;
let branch = repo.find_branch(branch_name, branch_type)?;

let annotated =
repo.reference_to_annotated_commit(&branch.into_reference())?;
Expand Down Expand Up @@ -268,7 +270,8 @@ mod test_conflict_free_rebase {

checkout_branch(repo_path, "refs/heads/foo").unwrap();

let res = rebase_branch(repo_path, "master");
let res =
rebase_branch(repo_path, "master", BranchType::Local);

assert!(matches!(res.unwrap(), RebaseState::Conflicted));

Expand All @@ -288,6 +291,7 @@ mod test_rebase {
tests::{repo_init, write_commit_file},
RepoState,
};
use git2::BranchType;

#[test]
fn test_conflicted_abort() {
Expand All @@ -312,7 +316,8 @@ mod test_rebase {

// rebase

let r = rebase_branch(repo_path, "master").unwrap();
let r = rebase_branch(repo_path, "master", BranchType::Local)
.unwrap();

assert_eq!(r, RebaseState::Conflicted);
assert_eq!(repo_state(repo_path).unwrap(), RepoState::Rebase);
Expand Down
28 changes: 22 additions & 6 deletions src/components/branchlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use asyncgit::{
checkout_remote_branch, BranchDetails, LocalBranch,
RemoteBranch,
},
checkout_branch, get_branches_info, BranchInfo, CommitId,
RepoState,
checkout_branch, get_branches_info, BranchInfo, BranchType,
CommitId, RepoState,
},
AsyncGitNotification, CWD,
};
Expand Down Expand Up @@ -178,15 +178,15 @@ impl Component for BranchListComponent {
&self.key_config,
),
!self.selection_is_cur_branch(),
self.local,
true,
));

out.push(CommandInfo::new(
strings::commands::branch_popup_rebase(
&self.key_config,
),
!self.selection_is_cur_branch(),
self.local,
true,
));

out.push(CommandInfo::new(
Expand Down Expand Up @@ -368,7 +368,11 @@ impl BranchListComponent {
if let Some(branch) =
self.branches.get(usize::from(self.selection))
{
sync::merge_branch(CWD, &branch.name)?;
sync::merge_branch(
CWD,
&branch.name,
self.get_branch_type(),
)?;

self.hide_and_switch_tab()?;
}
Expand All @@ -380,14 +384,26 @@ impl BranchListComponent {
if let Some(branch) =
self.branches.get(usize::from(self.selection))
{
sync::rebase_branch(CWD, &branch.name)?;
sync::rebase_branch(
CWD,
&branch.name,
self.get_branch_type(),
)?;

self.hide_and_switch_tab()?;
}

Ok(())
}

const fn get_branch_type(&self) -> BranchType {
if self.local {
BranchType::Local
} else {
BranchType::Remote
}
}

fn hide_and_switch_tab(&mut self) -> Result<()> {
self.hide();
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
Expand Down

0 comments on commit 153c79a

Please sign in to comment.