From 6d4335337cec7cdde87f63d6662f4d29d05f76ea Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sun, 2 Nov 2014 00:13:58 -0400 Subject: [PATCH] Use load_repo_head() when reloading refs This ensures that the HEAD and HEAD ID is always in sync. --- src/refdb.c | 11 ++-------- test/refs/branch-checkout-test | 49 +++++++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/refdb.c b/src/refdb.c index 8fd3805..d305d57 100644 --- a/src/refdb.c +++ b/src/refdb.c @@ -216,9 +216,6 @@ read_ref(char *id, size_t idlen, char *name, size_t namelen, void *data) static int reload_refs(bool force) { - const char *head_argv[] = { - "git", "symbolic-ref", "HEAD", NULL - }; const char *ls_remote_argv[SIZEOF_ARG] = { "git", "ls-remote", repo.git_dir, NULL }; @@ -236,12 +233,8 @@ reload_refs(bool force) if (!*repo.git_dir) return OK; - if ((force || !*repo.head) && io_run_buf(head_argv, repo.head, sizeof(repo.head)) && - !prefixcmp(repo.head, "refs/heads/")) { - char *offset = repo.head + STRING_SIZE("refs/heads/"); - - memmove(repo.head, offset, strlen(offset) + 1); - } + if (force || !*repo.head) + load_repo_head(); if (strcmp(old_repo.head, repo.head)) opt.changed |= WATCH_HEAD; diff --git a/test/refs/branch-checkout-test b/test/refs/branch-checkout-test index 0f8c576..154622f 100755 --- a/test/refs/branch-checkout-test +++ b/test/refs/branch-checkout-test @@ -6,6 +6,7 @@ . libgit.sh export LINES=9 +export COLUMNS=90 steps ' :save-display refs-init.screen @@ -60,34 +61,34 @@ $LONG_TAG_NAME_ID EOF assert_equals 'refs-init.screen' <