mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 17:08:21 +00:00
Fix exit on fetching a branch that has no upstream/remote (#638)
* do not assume remote/upstream of a branch anymore
This commit is contained in:
parent
6594a8d31c
commit
ee5b9d9f4e
7 changed files with 29 additions and 24 deletions
|
|
@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## Unreleased
|
||||
|
||||
### Fixed
|
||||
- fetch crashed when no upstream of branch is set ([#637](https://github.com/extrawurst/gitui/issues/637))
|
||||
|
||||
## [0.14.0] - 2020-04-11
|
||||
|
||||
### Added
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::{
|
|||
error::{Error, Result},
|
||||
sync::{
|
||||
cred::BasicAuthCredential,
|
||||
remotes::{fetch_origin, push::ProgressNotification},
|
||||
remotes::{fetch, push::ProgressNotification},
|
||||
},
|
||||
AsyncNotification, RemoteProgress, CWD,
|
||||
};
|
||||
|
|
@ -91,7 +91,7 @@ impl AsyncFetch {
|
|||
arc_progress,
|
||||
);
|
||||
|
||||
let res = fetch_origin(
|
||||
let res = fetch(
|
||||
CWD,
|
||||
¶ms.branch,
|
||||
params.basic_credential,
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ mod test {
|
|||
use super::*;
|
||||
use crate::sync::{
|
||||
branch_compare_upstream,
|
||||
remotes::{fetch_origin, push::push},
|
||||
remotes::{fetch, push::push},
|
||||
tests::{
|
||||
debug_cmd_print, get_commit_ids, repo_clone,
|
||||
repo_init_bare, write_commit_file,
|
||||
|
|
@ -146,8 +146,7 @@ mod test {
|
|||
.is_err());
|
||||
|
||||
//lets fetch from origin
|
||||
let bytes =
|
||||
fetch_origin(clone2_dir, "master", None, None).unwrap();
|
||||
let bytes = fetch(clone2_dir, "master", None, None).unwrap();
|
||||
assert!(bytes > 0);
|
||||
|
||||
//we should be one commit behind
|
||||
|
|
@ -218,7 +217,7 @@ mod test {
|
|||
|
||||
write_commit_file(&clone2, "test.bin", "foobar", "commit2");
|
||||
|
||||
let bytes = fetch_origin(
|
||||
let bytes = fetch(
|
||||
clone2_dir.path().to_str().unwrap(),
|
||||
"master",
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ pub fn branch_merge_upstream_fastforward(
|
|||
pub mod test {
|
||||
use super::*;
|
||||
use crate::sync::{
|
||||
remotes::{fetch_origin, push::push},
|
||||
remotes::{fetch, push::push},
|
||||
tests::{
|
||||
debug_cmd_print, get_commit_ids, repo_clone,
|
||||
repo_init_bare, write_commit_file,
|
||||
|
|
@ -106,7 +106,7 @@ pub mod test {
|
|||
|
||||
// clone1 again
|
||||
|
||||
let bytes = fetch_origin(
|
||||
let bytes = fetch(
|
||||
clone1_dir.path().to_str().unwrap(),
|
||||
"master",
|
||||
None,
|
||||
|
|
@ -115,7 +115,7 @@ pub mod test {
|
|||
.unwrap();
|
||||
assert!(bytes > 0);
|
||||
|
||||
let bytes = fetch_origin(
|
||||
let bytes = fetch(
|
||||
clone1_dir.path().to_str().unwrap(),
|
||||
"master",
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ mod test {
|
|||
use super::*;
|
||||
use crate::sync::{
|
||||
branch_compare_upstream, get_commits_info,
|
||||
remotes::{fetch_origin, push::push},
|
||||
remotes::{fetch, push::push},
|
||||
tests::{
|
||||
debug_cmd_print, get_commit_ids, repo_clone,
|
||||
repo_init_bare, write_commit_file,
|
||||
|
|
@ -133,8 +133,7 @@ mod test {
|
|||
assert_eq!(clone1.head_detached().unwrap(), false);
|
||||
|
||||
//lets fetch from origin
|
||||
let bytes =
|
||||
fetch_origin(clone1_dir, "master", None, None).unwrap();
|
||||
let bytes = fetch(clone1_dir, "master", None, None).unwrap();
|
||||
assert!(bytes > 0);
|
||||
|
||||
//we should be one commit behind
|
||||
|
|
@ -204,7 +203,7 @@ mod test {
|
|||
|
||||
//lets fetch from origin
|
||||
|
||||
fetch_origin(clone1_dir, "master", None, None).unwrap();
|
||||
fetch(clone1_dir, "master", None, None).unwrap();
|
||||
|
||||
merge_upstream_rebase(clone1_dir, "master").unwrap();
|
||||
|
||||
|
|
@ -266,8 +265,7 @@ mod test {
|
|||
let _commit3 =
|
||||
write_commit_file(&clone1, "test2.txt", "foo", "commit3");
|
||||
|
||||
let bytes =
|
||||
fetch_origin(clone1_dir, "master", None, None).unwrap();
|
||||
let bytes = fetch(clone1_dir, "master", None, None).unwrap();
|
||||
assert!(bytes > 0);
|
||||
|
||||
assert_eq!(
|
||||
|
|
|
|||
|
|
@ -11,9 +11,10 @@ use crate::{
|
|||
},
|
||||
};
|
||||
use crossbeam_channel::Sender;
|
||||
use git2::{FetchOptions, Repository};
|
||||
use git2::{BranchType, FetchOptions, Repository};
|
||||
use push::remote_callbacks;
|
||||
use scopetime::scope_time;
|
||||
use utils::bytes2string;
|
||||
|
||||
/// origin
|
||||
pub const DEFAULT_REMOTE_NAME: &str = "origin";
|
||||
|
|
@ -71,8 +72,8 @@ pub(crate) fn get_default_remote_in_repo(
|
|||
Err(Error::NoDefaultRemoteFound)
|
||||
}
|
||||
|
||||
///
|
||||
pub(crate) fn fetch_origin(
|
||||
/// fetches from upstream/remote for `branch`
|
||||
pub(crate) fn fetch(
|
||||
repo_path: &str,
|
||||
branch: &str,
|
||||
basic_credential: Option<BasicAuthCredential>,
|
||||
|
|
@ -81,8 +82,13 @@ pub(crate) fn fetch_origin(
|
|||
scope_time!("fetch_origin");
|
||||
|
||||
let repo = utils::repo(repo_path)?;
|
||||
let mut remote =
|
||||
repo.find_remote(&get_default_remote_in_repo(&repo)?)?;
|
||||
let branch_ref = repo
|
||||
.find_branch(branch, BranchType::Local)?
|
||||
.into_reference();
|
||||
let branch_ref = bytes2string(branch_ref.name_bytes())?;
|
||||
let remote_name = repo.branch_upstream_remote(&branch_ref)?;
|
||||
let remote_name = bytes2string(&*remote_name)?;
|
||||
let mut remote = repo.find_remote(&remote_name)?;
|
||||
|
||||
let mut options = FetchOptions::new();
|
||||
options.remote_callbacks(remote_callbacks(
|
||||
|
|
@ -117,7 +123,7 @@ mod tests {
|
|||
|
||||
assert_eq!(remotes, vec![String::from("origin")]);
|
||||
|
||||
fetch_origin(repo_path, "master", None, None).unwrap();
|
||||
fetch(repo_path, "master", None, None).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ mod tests {
|
|||
use super::*;
|
||||
use crate::sync::{
|
||||
self,
|
||||
remotes::{fetch_origin, push::push},
|
||||
remotes::{fetch, push::push},
|
||||
tests::{repo_clone, repo_init_bare},
|
||||
};
|
||||
use sync::tests::write_commit_file;
|
||||
|
|
@ -195,8 +195,7 @@ mod tests {
|
|||
assert_eq!(sync::get_tags(clone2_dir).unwrap().len(), 0);
|
||||
|
||||
//lets fetch from origin
|
||||
let bytes =
|
||||
fetch_origin(clone2_dir, "master", None, None).unwrap();
|
||||
let bytes = fetch(clone2_dir, "master", None, None).unwrap();
|
||||
assert!(bytes > 0);
|
||||
|
||||
sync::merge_upstream_commit(clone2_dir, "master").unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue