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> {
|
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();
|
let mut fo = FetchOptions::new();
|
||||||
fo.download_tags(git2::AutotagOption::All);
|
fo.download_tags(git2::AutotagOption::All);
|
||||||
repo.find_remote("origin")?.fetch(&branches, Some(&mut fo), None)?;
|
|
||||||
|
|
||||||
for branch in branches {
|
for branch in branches {
|
||||||
let refname = format!("refs/remotes/origin/{}", branch);
|
let refname = format!("refs/remotes/origin/{}", branch);
|
||||||
|
@ -113,6 +112,7 @@ impl Refractr {
|
||||||
ssh_key: &String,
|
ssh_key: &String,
|
||||||
strict: bool,
|
strict: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
common::verbose(self.verbose, 2, format!("Fetching repo"));
|
||||||
let mut fo = FetchOptions::new();
|
let mut fo = FetchOptions::new();
|
||||||
if ssh {
|
if ssh {
|
||||||
match self.set_up_ssh(ssh_key.clone(), strict.clone()) {
|
match self.set_up_ssh(ssh_key.clone(), strict.clone()) {
|
||||||
|
@ -406,14 +406,51 @@ impl Refractr {
|
||||||
repo_dir
|
repo_dir
|
||||||
));
|
));
|
||||||
match Repository::open(Path::new(&repo_dir)) {
|
match Repository::open(Path::new(&repo_dir)) {
|
||||||
Ok(r) => match self.fast_forward(&r, &cfg.config.branches) {
|
Ok(r) => {
|
||||||
Ok(_) => r,
|
if let Ok(rem) = r.find_remote("origin") {
|
||||||
Err(e) => {
|
match rem.url() {
|
||||||
return Err(ReturnData {
|
Some(url) => {
|
||||||
code: ExitCode::RepositoryError,
|
if url != &cfg.config.from {
|
||||||
msg: format!("failed to fast forward existing repo: {}", e),
|
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) => {
|
Err(e) => {
|
||||||
return Err(ReturnData {
|
return Err(ReturnData {
|
||||||
|
@ -431,18 +468,6 @@ impl Refractr {
|
||||||
ExitCode::RepositoryError,
|
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) {
|
let remotes = match self.make_remotes(&repo, &cfg) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
|
|
Loading…
Add table
Reference in a new issue