From 3448d1cd6a3a3bedd0668c6b6b60fd545a3614ed Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Wed, 9 Sep 2015 09:16:31 +0200 Subject: [PATCH] Fix git-worktree support Use git-show-ref instead of git-ls-remote to properly list references in worktrees. The latter was failing with: $ git ls-remote /opt/tig/test/tmp/status/worktree-test/repo/.git/worktrees/work dir fatal: '/opt/tig/test/tmp/status/worktree-test/repo/.git/worktrees/work dir' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists Initial test case provided by stenja. Fixes #437 --- NEWS.adoc | 2 ++ src/refdb.c | 4 ++-- test/refs/worktree-test | 31 +++++++++++++++++++++++++++++++ test/status/worktree-test | 30 ++++++++++++++++++++++++++++++ test/tools/libgit.sh | 13 +++++++++++++ 5 files changed, 78 insertions(+), 2 deletions(-) create mode 100755 test/refs/worktree-test create mode 100755 test/status/worktree-test diff --git a/NEWS.adoc b/NEWS.adoc index 7cc9240..02f6085 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -25,6 +25,7 @@ Improvements: - Expose repository variables to external commands, e.g. `%(repo:head)` gives the branch name of the current HEAD and `%(repo:cdup)` for the repo root path. - Add `make uninstall`. (GH #417) + - Add ZSH completion file (based on Bash completion) (GH #433) Bug fixes: @@ -35,6 +36,7 @@ Bug fixes: - Fix out of bounds read in graph-v2 module. (GH #402) - Add currently checked out branch to `%(branch)`. (GH #416) - Size diff stats correctly for split views. + - Fix `git-worktree` support. (GH #437) tig-2.1 ------- diff --git a/src/refdb.c b/src/refdb.c index 95a2137..ae1ff99 100644 --- a/src/refdb.c +++ b/src/refdb.c @@ -307,7 +307,7 @@ static enum status_code reload_refs(bool force) { const char *ls_remote_argv[SIZEOF_ARG] = { - "git", "ls-remote", repo.git_dir, NULL + "git", "show-ref", "--head", "--dereference", NULL }; static bool init = false; struct ref_opt opt = { repo.remote, repo.head, WATCH_NONE }; @@ -334,7 +334,7 @@ reload_refs(bool force) string_map_clear(&refs_by_id); string_map_foreach(&refs_by_name, invalidate_refs, NULL); - code = io_run_load(ls_remote_argv, "\t", read_ref, &opt); + code = io_run_load(ls_remote_argv, " ", read_ref, &opt); if (code != SUCCESS) return code; diff --git a/test/refs/worktree-test b/test/refs/worktree-test new file mode 100755 index 0000000..cdd0baf --- /dev/null +++ b/test/refs/worktree-test @@ -0,0 +1,31 @@ +#!/bin/sh +# +# Test for GitHub issue #437 +# Mainly to document the behavior of the refs view in "worktree"s. + +. libtest.sh +. libgit.sh + +export LINES=9 + +test_setup_work_dir() +{ + create_worktree +} + +steps ' + :save-display worktree.screen +' + +test_tig refs + +assert_equals 'worktree.screen' <