do more things if a repo exists
This commit is contained in:
parent
1690131e4f
commit
b98a3beec4
1 changed files with 47 additions and 22 deletions
|
@ -91,10 +91,9 @@ impl Refractr {
|
|||
}
|
||||
|
||||
fn fast_forward(&self, repo: &Repository, branches: &Vec<String>) -> Result<(), Error> {
|
||||
common::verbose(self.verbose, 2, format!("Pulling origin"));
|
||||
common::verbose(self.verbose, 2, format!("Fast forwarding repo"));
|
||||
let mut fo = FetchOptions::new();
|
||||
fo.download_tags(git2::AutotagOption::All);
|
||||
repo.find_remote("origin")?.fetch(&branches, Some(&mut fo), None)?;
|
||||
|
||||
for branch in branches {
|
||||
let refname = format!("refs/remotes/origin/{}", branch);
|
||||
|
@ -113,6 +112,7 @@ impl Refractr {
|
|||
ssh_key: &String,
|
||||
strict: bool,
|
||||
) -> Result<(), Error> {
|
||||
common::verbose(self.verbose, 2, format!("Fetching repo"));
|
||||
let mut fo = FetchOptions::new();
|
||||
if ssh {
|
||||
match self.set_up_ssh(ssh_key.clone(), strict.clone()) {
|
||||
|
@ -406,14 +406,51 @@ impl Refractr {
|
|||
repo_dir
|
||||
));
|
||||
match Repository::open(Path::new(&repo_dir)) {
|
||||
Ok(r) => match self.fast_forward(&r, &cfg.config.branches) {
|
||||
Ok(_) => r,
|
||||
Err(e) => {
|
||||
return Err(ReturnData {
|
||||
code: ExitCode::RepositoryError,
|
||||
msg: format!("failed to fast forward existing repo: {}", e),
|
||||
});
|
||||
},
|
||||
Ok(r) => {
|
||||
if let Ok(rem) = r.find_remote("origin") {
|
||||
match rem.url() {
|
||||
Some(url) => {
|
||||
if url != &cfg.config.from {
|
||||
return Err(ReturnData {
|
||||
code: ExitCode::RepositoryError,
|
||||
msg: format!(
|
||||
"existing repo's origin does not match 'from' value in config: {}",
|
||||
url
|
||||
),
|
||||
});
|
||||
}
|
||||
},
|
||||
None => {
|
||||
return Err(ReturnData {
|
||||
code: ExitCode::RepositoryError,
|
||||
msg: format!("could not obtain existing repo's origin: {}", repo_dir),
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
// fetch updates for the repo
|
||||
if let Err(e) = self.fetch(
|
||||
&r,
|
||||
&cfg.config.branches,
|
||||
ssh,
|
||||
&cfg.config.git.ssh_identity_file,
|
||||
self.strict.clone(),
|
||||
) {
|
||||
common::error(
|
||||
format!("failed to fetch repo {}: {}", cfg.config.from, e),
|
||||
ExitCode::FetchError,
|
||||
);
|
||||
}
|
||||
// fast forward
|
||||
match self.fast_forward(&r, &cfg.config.branches) {
|
||||
Ok(_) => r,
|
||||
Err(e) => {
|
||||
return Err(ReturnData {
|
||||
code: ExitCode::RepositoryError,
|
||||
msg: format!("failed to fast forward existing repo: {}", e),
|
||||
});
|
||||
},
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
return Err(ReturnData {
|
||||
|
@ -431,18 +468,6 @@ impl Refractr {
|
|||
ExitCode::RepositoryError,
|
||||
);
|
||||
}
|
||||
if let Err(e) = self.fetch(
|
||||
&repo,
|
||||
&cfg.config.branches,
|
||||
ssh,
|
||||
&cfg.config.git.ssh_identity_file,
|
||||
self.strict.clone(),
|
||||
) {
|
||||
common::error(
|
||||
format!("failed to fetch repo {}: {}", cfg.config.from, e),
|
||||
ExitCode::FetchError,
|
||||
);
|
||||
}
|
||||
|
||||
let remotes = match self.make_remotes(&repo, &cfg) {
|
||||
Ok(v) => v,
|
||||
|
|
Loading…
Add table
Reference in a new issue