Skip to content

Commit

Permalink
Always (re)set the branch to FETCH_HEAD instead of trying to parse it
Browse files Browse the repository at this point in the history
Closes #141
  • Loading branch information
nabijaczleweli committed Aug 14, 2020
1 parent 5ebebb3 commit 988fabe
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
//! continue with doing whatever you wish.

use git2::{self, Error as GitError, Config as GitConfig, Cred as GitCred, RemoteCallbacks, CredentialType, FetchOptions, ProxyOptions, BranchType, Repository,
Tree, Oid};
use git2::{self, Config as GitConfig, Error as GitError, Cred as GitCred, RemoteCallbacks, CredentialType, FetchOptions, ProxyOptions, Repository, Tree, Oid};
use semver::{VersionReq as SemverReq, Version as Semver};
use std::collections::BTreeMap;
use std::path::{PathBuf, Path};
Expand Down Expand Up @@ -494,20 +493,16 @@ impl GitRepoPackage {
})
.map_err(|e| panic!("Fetching {} from {}: {}", clone_dir.display(), self.url, e))
.unwrap();
r.find_branch(&branch, BranchType::Local)
.map_err(|e| panic!("Local branch {} doesn't exist in {}: {}", branch, clone_dir.display(), e))
.unwrap()
.into_reference()
.set_target(r.find_reference("FETCH_HEAD")
.map_err(|e| panic!("No FETCH_HEAD in {}: {}", clone_dir.display(), e))
.unwrap()
.target()
.ok_or_else(|| panic!("FETCH_HEAD a symbolic reference in {}", clone_dir.display()))
.unwrap(),
concat!(crate_name!(), " v", crate_version!()))
.map_err(|e| panic!("Updating local branch {} in {}: {}", branch, clone_dir.display(), e))
r.branch(&branch,
&r.find_reference("FETCH_HEAD")
.map_err(|e| panic!("No FETCH_HEAD in {}: {}", clone_dir.display(), e))
.unwrap()
.peel_to_commit()
.map_err(|e| panic!("FETCH_HEAD not a commit in {}: {}", clone_dir.display(), e))
.unwrap(),
true)
.map_err(|e| panic!("Setting local branch {} in {}: {}", branch, clone_dir.display(), e))
.unwrap();

Ok(r)
} else {
// If we could not open the repository either it does not exist, or exists but is invalid.
Expand Down

0 comments on commit 988fabe

Please sign in to comment.