mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
git-storage: fix up old broken local caches to use the right branch
If you had one of the unfortunate local git caches with a local HEAD just pointing to 'master', this will make note of that and then fix it up to use the proper branch name in the cache repository. [Dirk Hohndel: demoted from error to fprintf as most users won't care] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
433149af19
commit
f4ffd7a8fb
1 changed files with 16 additions and 0 deletions
|
@ -652,6 +652,7 @@ static git_repository *update_local_repo(const char *localdir, const char *remot
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
git_repository *repo = NULL;
|
git_repository *repo = NULL;
|
||||||
|
git_reference *head;
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
fprintf(stderr, "git storage: update local repo\n");
|
fprintf(stderr, "git storage: update local repo\n");
|
||||||
|
@ -664,6 +665,21 @@ static git_repository *update_local_repo(const char *localdir, const char *remot
|
||||||
report_error("Unable to open git cache repository at %s: %s", localdir, giterr_last()->message);
|
report_error("Unable to open git cache repository at %s: %s", localdir, giterr_last()->message);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check the HEAD being the right branch */
|
||||||
|
if (!git_repository_head(&head, repo)) {
|
||||||
|
const char *name;
|
||||||
|
if (!git_branch_name(&name, head)) {
|
||||||
|
if (strcmp(name, branch)) {
|
||||||
|
char *branchref = format_string("refs/heads/%s", branch);
|
||||||
|
fprintf(stderr, "Setting cache branch from '%s' to '%s'", name, branch);
|
||||||
|
git_repository_set_head(repo, branchref);
|
||||||
|
free(branchref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
git_reference_free(head);
|
||||||
|
}
|
||||||
|
|
||||||
if (!git_local_only)
|
if (!git_local_only)
|
||||||
sync_with_remote(repo, remote, branch, rt);
|
sync_with_remote(repo, remote, branch, rt);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue