diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2020-04-14 15:16:36 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-04-15 07:58:10 -0700 |
commit | f4ffd7a8fb412b896a05ba32ddca9573e9ddc7bf (patch) | |
tree | aa3c2aeb2c63f266461de41751685731df5fa809 | |
parent | 433149af19c0d0424383f756500c4f0b7d1cd831 (diff) | |
download | subsurface-f4ffd7a8fb412b896a05ba32ddca9573e9ddc7bf.tar.gz |
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>
-rw-r--r-- | core/git-access.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/core/git-access.c b/core/git-access.c index b015524cb..1a18746d8 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -652,6 +652,7 @@ static git_repository *update_local_repo(const char *localdir, const char *remot { int error; git_repository *repo = NULL; + git_reference *head; if (verbose) 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); 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) sync_with_remote(repo, remote, branch, rt); |