step sixty two: don't allow force push
This commit is contained in:
parent
4e1988997a
commit
687c9a8a4a
11
src/base.rs
11
src/base.rs
|
@ -459,6 +459,17 @@ pub fn get_working_tree() -> HashMap<String, String> {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_ancestor_of(commit: String, maybe_ancestor: String) -> bool {
|
||||||
|
let mut commits = VecDeque::new();
|
||||||
|
commits.push_front(commit);
|
||||||
|
for oid in iter_commits_and_parents(commits) {
|
||||||
|
if maybe_ancestor == oid {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
fn empty_current_directory(dir: &str) -> io::Result<()> {
|
fn empty_current_directory(dir: &str) -> io::Result<()> {
|
||||||
// Delete current directory, except the ignored directories and files
|
// Delete current directory, except the ignored directories and files
|
||||||
for entry in fs::read_dir(dir)? {
|
for entry in fs::read_dir(dir)? {
|
||||||
|
|
|
@ -31,9 +31,17 @@ pub fn fetch(path: String) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push(remote_path: String, reference: String) {
|
pub fn push(remote_path: String, reference: String) {
|
||||||
|
let refs = get_remote_refs(remote_path.clone(), REMOTE_REFS_BASE);
|
||||||
|
let empty = "".to_owned();
|
||||||
|
let remote_ref = refs.get(&reference).unwrap_or(&empty);
|
||||||
let local_ref = data::get_ref(reference.clone(), true).value;
|
let local_ref = data::get_ref(reference.clone(), true).value;
|
||||||
assert!(local_ref != "".to_string());
|
assert!(local_ref != "".to_string());
|
||||||
|
|
||||||
|
// Don't allow force push
|
||||||
|
assert!(
|
||||||
|
*remote_ref == "".to_owned() || base::is_ancestor_of(local_ref.clone(), remote_ref.clone())
|
||||||
|
);
|
||||||
|
|
||||||
let commit_oids = vec![&local_ref];
|
let commit_oids = vec![&local_ref];
|
||||||
base::copy_objects_in_commits_and_parents(commit_oids, remote_path.clone(), true);
|
base::copy_objects_in_commits_and_parents(commit_oids, remote_path.clone(), true);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue