Skip to content

Commit 153c79a

Browse files
authored
support pull from remote (#945)
closes #920
1 parent 31f6771 commit 153c79a

File tree

5 files changed

+42
-14
lines changed

5 files changed

+42
-14
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

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

1314
## [0.18] - 2021-10-11
1415

Diff for: asyncgit/src/sync/merge.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ pub fn abort_merge(repo_path: &str) -> Result<()> {
4646
}
4747

4848
///
49-
pub fn merge_branch(repo_path: &str, branch: &str) -> Result<()> {
49+
pub fn merge_branch(
50+
repo_path: &str,
51+
branch: &str,
52+
branch_type: BranchType,
53+
) -> Result<()> {
5054
scope_time!("merge_branch");
5155

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

54-
merge_branch_repo(&repo, branch)?;
58+
merge_branch_repo(&repo, branch, branch_type)?;
5559

5660
Ok(())
5761
}
@@ -89,8 +93,9 @@ pub fn abort_pending_rebase(repo_path: &str) -> Result<()> {
8993
pub fn merge_branch_repo(
9094
repo: &Repository,
9195
branch: &str,
96+
branch_type: BranchType,
9297
) -> Result<()> {
93-
let branch = repo.find_branch(branch, BranchType::Local)?;
98+
let branch = repo.find_branch(branch, branch_type)?;
9499

95100
let annotated =
96101
repo.reference_to_annotated_commit(&branch.into_reference())?;
@@ -162,7 +167,7 @@ mod tests {
162167

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

165-
merge_branch(repo_path, "master").unwrap();
170+
merge_branch(repo_path, "master", BranchType::Local).unwrap();
166171

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

Diff for: asyncgit/src/sync/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub use config::{
5151
ShowUntrackedFilesConfig,
5252
};
5353
pub use diff::get_diff_commit;
54+
pub use git2::BranchType;
5455
pub use hooks::{
5556
hooks_commit_msg, hooks_post_commit, hooks_pre_commit, HookResult,
5657
};

Diff for: asyncgit/src/sync/rebase.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,21 @@ use super::CommitId;
1212
pub fn rebase_branch(
1313
repo_path: &str,
1414
branch: &str,
15+
branch_type: BranchType,
1516
) -> Result<RebaseState> {
1617
scope_time!("rebase_branch");
1718

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

20-
rebase_branch_repo(&repo, branch)
21+
rebase_branch_repo(&repo, branch, branch_type)
2122
}
2223

2324
fn rebase_branch_repo(
2425
repo: &Repository,
2526
branch_name: &str,
27+
branch_type: BranchType,
2628
) -> Result<RebaseState> {
27-
let branch = repo.find_branch(branch_name, BranchType::Local)?;
29+
let branch = repo.find_branch(branch_name, branch_type)?;
2830

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

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

271-
let res = rebase_branch(repo_path, "master");
273+
let res =
274+
rebase_branch(repo_path, "master", BranchType::Local);
272275

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

@@ -288,6 +291,7 @@ mod test_rebase {
288291
tests::{repo_init, write_commit_file},
289292
RepoState,
290293
};
294+
use git2::BranchType;
291295

292296
#[test]
293297
fn test_conflicted_abort() {
@@ -312,7 +316,8 @@ mod test_rebase {
312316

313317
// rebase
314318

315-
let r = rebase_branch(repo_path, "master").unwrap();
319+
let r = rebase_branch(repo_path, "master", BranchType::Local)
320+
.unwrap();
316321

317322
assert_eq!(r, RebaseState::Conflicted);
318323
assert_eq!(repo_state(repo_path).unwrap(), RepoState::Rebase);

Diff for: src/components/branchlist.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use asyncgit::{
1818
checkout_remote_branch, BranchDetails, LocalBranch,
1919
RemoteBranch,
2020
},
21-
checkout_branch, get_branches_info, BranchInfo, CommitId,
22-
RepoState,
21+
checkout_branch, get_branches_info, BranchInfo, BranchType,
22+
CommitId, RepoState,
2323
},
2424
AsyncGitNotification, CWD,
2525
};
@@ -178,15 +178,15 @@ impl Component for BranchListComponent {
178178
&self.key_config,
179179
),
180180
!self.selection_is_cur_branch(),
181-
self.local,
181+
true,
182182
));
183183

184184
out.push(CommandInfo::new(
185185
strings::commands::branch_popup_rebase(
186186
&self.key_config,
187187
),
188188
!self.selection_is_cur_branch(),
189-
self.local,
189+
true,
190190
));
191191

192192
out.push(CommandInfo::new(
@@ -368,7 +368,11 @@ impl BranchListComponent {
368368
if let Some(branch) =
369369
self.branches.get(usize::from(self.selection))
370370
{
371-
sync::merge_branch(CWD, &branch.name)?;
371+
sync::merge_branch(
372+
CWD,
373+
&branch.name,
374+
self.get_branch_type(),
375+
)?;
372376

373377
self.hide_and_switch_tab()?;
374378
}
@@ -380,14 +384,26 @@ impl BranchListComponent {
380384
if let Some(branch) =
381385
self.branches.get(usize::from(self.selection))
382386
{
383-
sync::rebase_branch(CWD, &branch.name)?;
387+
sync::rebase_branch(
388+
CWD,
389+
&branch.name,
390+
self.get_branch_type(),
391+
)?;
384392

385393
self.hide_and_switch_tab()?;
386394
}
387395

388396
Ok(())
389397
}
390398

399+
const fn get_branch_type(&self) -> BranchType {
400+
if self.local {
401+
BranchType::Local
402+
} else {
403+
BranchType::Remote
404+
}
405+
}
406+
391407
fn hide_and_switch_tab(&mut self) -> Result<()> {
392408
self.hide();
393409
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));

0 commit comments

Comments
 (0)