Clean up old remotes
This commit is contained in:
parent
0b29ffc410
commit
3006d1b571
52
src/lib.rs
52
src/lib.rs
@ -1,4 +1,4 @@
|
||||
use git2::{Cred, Error, FetchOptions, Index, IndexEntry, IndexTime, Oid, Progress, PushOptions, RemoteCallbacks, Repository};
|
||||
use git2::{Cred, Error, FetchOptions, Index, Progress, PushOptions, RemoteCallbacks, Repository};
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use log::{info, trace};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
@ -51,8 +51,8 @@ impl BenchmarkRepository
|
||||
{
|
||||
match status
|
||||
{
|
||||
None => trace!("Reference “{}” pushed successfully to remote “origin”", reference),
|
||||
Some(error) => panic!("Couldn’t push reference “{}” to remote “origin”: {}", reference, error),
|
||||
None => trace!("reference “{}” pushed successfully to remote “origin”", reference),
|
||||
Some(error) => panic!("couldn’t push reference “{}” to remote “origin”: {}", reference, error),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
@ -63,10 +63,10 @@ impl BenchmarkRepository
|
||||
if let Err(error) = self.repository.find_remote("origin")
|
||||
.or_else(|_| self.repository.remote("origin", remote_url))
|
||||
{
|
||||
panic!("Could not reset remote “origin”: {}", error);
|
||||
panic!("could not reset remote “origin”: {}", error);
|
||||
}
|
||||
|
||||
info!("Reset origin to “{}”", remote_url);
|
||||
info!("reset origin to “{}”", remote_url);
|
||||
|
||||
self
|
||||
}
|
||||
@ -115,6 +115,39 @@ impl BenchmarkRepository
|
||||
self
|
||||
}
|
||||
|
||||
fn clean_up_remotes(&self) -> &Self
|
||||
{
|
||||
let remotes = match self.repository.remotes()
|
||||
{
|
||||
Ok(remotes) => remotes,
|
||||
Err(error) => panic!("could not enumerate remotes: {}", error),
|
||||
};
|
||||
|
||||
for remote in remotes.iter()
|
||||
{
|
||||
let remote = match remote
|
||||
{
|
||||
Some(remote) => remote,
|
||||
None => panic!("remote name not in UTF-8"),
|
||||
};
|
||||
|
||||
if remote == "origin"
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
match self.repository.remote_delete(remote)
|
||||
{
|
||||
Ok(()) => (),
|
||||
Err(error) => panic!("could not clean up remote “{}”: {}", remote, error),
|
||||
};
|
||||
}
|
||||
|
||||
trace!("cleaned up remotes");
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
fn init(base_path: &Path) -> Repository
|
||||
{
|
||||
let repository_path = base_path.join("upstream");
|
||||
@ -125,7 +158,7 @@ impl BenchmarkRepository
|
||||
Err(error) => panic!("failed to initialize Git repository in “{}”: {}", repository_path.display(), error),
|
||||
};
|
||||
|
||||
info!("Initialized Git repository in “{}”", repository_path.display());
|
||||
info!("initialized Git repository in “{}”", repository_path.display());
|
||||
|
||||
repository
|
||||
}
|
||||
@ -155,7 +188,8 @@ impl BenchmarkRepository
|
||||
benchmark_repository
|
||||
.reset_origin(remote_url)
|
||||
.fetch_branch("origin", "config")
|
||||
.fetch_branch("origin", "results");
|
||||
.fetch_branch("origin", "results")
|
||||
.clean_up_remotes();
|
||||
|
||||
benchmark_repository
|
||||
}
|
||||
@ -415,7 +449,7 @@ impl BenchmarkRepository
|
||||
match self.repository.remote(&remote_name, &format!("file://{}", std::fs::canonicalize(&result_repository_path).unwrap().display()))
|
||||
{
|
||||
Ok(_) => (),
|
||||
Err(error) => panic!("cannot create remote: {}", error),
|
||||
Err(error) => panic!("could not create remote: {}", error),
|
||||
};
|
||||
|
||||
info!("initialized result Git repository for job {} in “{}”", id, result_repository_path.display());
|
||||
@ -478,7 +512,7 @@ impl BenchmarkRepository
|
||||
let job_tree = match job_commit.tree()
|
||||
{
|
||||
Ok(value) => value,
|
||||
Err(error) => panic!("cannot read results of job {}: {}", job_id, error),
|
||||
Err(error) => panic!("could not read results of job {}: {}", job_id, error),
|
||||
};
|
||||
|
||||
let mut upstream_index = match Index::new()
|
||||
|
Loading…
Reference in New Issue
Block a user