mirror of
https://gitlab.redox-os.org/redox-os/redox.git
synced 2026-06-25 14:24:18 +08:00
Handle git annotated tag and git gc
This commit is contained in:
parent
0f7323e47a
commit
9b38bd81f9
@ -238,39 +238,43 @@ pub fn fetch(recipe: &CookRecipe, check_source: bool, logger: &PtyOut) -> Result
|
||||
run_command(command, logger)?;
|
||||
|
||||
let (head_rev, detached_rev) = get_git_head_rev(&source_dir)?;
|
||||
if rev.is_some() {
|
||||
if !detached_rev {
|
||||
false
|
||||
} else if let Some(rev) = rev
|
||||
&& let Ok(exp_rev) = get_git_tag_rev(&source_dir, &rev)
|
||||
{
|
||||
exp_rev == head_rev
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else if detached_rev {
|
||||
false
|
||||
} else {
|
||||
let (_, remote_branch, remote_name, remote_url) =
|
||||
get_git_remote_tracking(&source_dir)?;
|
||||
// TODO: how to get default branch and compare it here?
|
||||
if let Some(branch) = branch
|
||||
&& branch != &remote_branch
|
||||
{
|
||||
false
|
||||
} else if remote_name != "origin" {
|
||||
false
|
||||
} else if &remote_url != chop_dot_git(git) {
|
||||
false
|
||||
} else {
|
||||
match get_git_fetch_rev(&source_dir, &remote_url, &remote_branch) {
|
||||
Ok(fetch_rev) => fetch_rev == head_rev,
|
||||
Err(e) => {
|
||||
log_to_pty!(logger, "{}", e);
|
||||
match (rev, detached_rev) {
|
||||
(Some(rev), true) => {
|
||||
if let Ok(exp_rev) = get_git_tag_rev(&source_dir, &rev) {
|
||||
exp_rev == head_rev
|
||||
} else {
|
||||
let mut command = Command::new("git");
|
||||
command.arg("-C").arg(&source_dir);
|
||||
command.arg("gc");
|
||||
run_command(command, logger)?;
|
||||
if let Ok(exp_rev) = get_git_tag_rev(&source_dir, &rev) {
|
||||
exp_rev == head_rev
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
(None, false) => {
|
||||
let (_, remote_branch, remote_name, remote_url) =
|
||||
get_git_remote_tracking(&source_dir)?;
|
||||
// TODO: how to get default branch and compare it here?
|
||||
if let Some(branch) = branch
|
||||
&& branch != &remote_branch
|
||||
{
|
||||
false
|
||||
} else if remote_name != "origin" || &remote_url != chop_dot_git(git) {
|
||||
false
|
||||
} else {
|
||||
match get_git_fetch_rev(&source_dir, &remote_url, &remote_branch) {
|
||||
Ok(fetch_rev) => fetch_rev == head_rev,
|
||||
Err(e) => {
|
||||
log_to_pty!(logger, "{}", e);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -301,13 +301,18 @@ pub fn get_git_ref_entry(dir: &PathBuf, entry: &str) -> Result<String> {
|
||||
// https://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery
|
||||
let git_refs = dir.join(".git/packed-refs");
|
||||
let refs_str = read_to_string(&git_refs)?;
|
||||
for line in refs_str.lines() {
|
||||
let mut lines = refs_str.lines();
|
||||
while let Some(line) = lines.next() {
|
||||
if line.contains(entry) {
|
||||
let sha = line
|
||||
let mut sha = line
|
||||
.split_whitespace()
|
||||
.next()
|
||||
.ok_or_else(wrap_other_err!("Packed-refs line is malformed"))?;
|
||||
|
||||
if let Some(next_line) = lines.next() {
|
||||
if next_line.starts_with('^') {
|
||||
sha = &next_line[1..];
|
||||
}
|
||||
}
|
||||
return Ok(sha.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user