From 15aab28834f9d1b447384bb79e6c5ae13314d651 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Thu, 11 Nov 2021 16:25:30 +0100 Subject: [PATCH] Remove quotes from TIG_LS_REMOTE to allow inline shell commands (#1161) The environment variable TIG_LS_REMOTE can be used to select the references that Tig will display. When using a command like TIG_LS_REMOTE='sh -c "a | b"' tig, we pass an argv-array with 3 elements to execvpe. The third argument is passed with quotes, which means that the shell tries to run a command that is literally called 'a | b'. Fix this by removing quotes. We already split arguments with a shell-like syntax, so this only improves compatibility. This makes it easier filter away unwanted refs (#1160) without creating a script TIG_LS_REMOTE. --- src/refdb.c | 2 +- test/refs/filter-test | 55 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100755 test/refs/filter-test diff --git a/src/refdb.c b/src/refdb.c index ae9444bfb..3595cce0a 100644 --- a/src/refdb.c +++ b/src/refdb.c @@ -325,7 +325,7 @@ reload_refs(bool force) int argc = 0; string_ncopy(ls_remote_cmd, env, strlen(env)); - if (!argv_from_string(ls_remote_argv, &argc, ls_remote_cmd)) + if (!argv_from_string_no_quotes(ls_remote_argv, &argc, ls_remote_cmd)) return error("Failed to parse TIG_LS_REMOTE: %s", env); } diff --git a/test/refs/filter-test b/test/refs/filter-test new file mode 100755 index 000000000..72c8e9c28 --- /dev/null +++ b/test/refs/filter-test @@ -0,0 +1,55 @@ +#!/bin/sh +# +# Test ref filtering (GitHub issue #1160) + +. libtest.sh +. libgit.sh + +export LINES=9 +export COLUMNS=120 + +git_init + +test_setup_work_dir() { + git_commit --allow-empty -m Initial\ commit + git branch my-branch1 HEAD + git branch my-branch2 HEAD + git update-ref refs/remotes/origin/my-branch1 HEAD + git update-ref refs/remotes/origin/my-branch2 HEAD + git tag my-tag1 HEAD + git tag my-tag2 HEAD + git update-ref refs/my-raw-ref1 HEAD + git update-ref refs/my-raw-ref2 HEAD +} + +export TIG_LS_REMOTE='sh -c "git show-ref --head --dereference | grep -v refs/.\\*1"' + +steps ' + :save-display main.screen + :view-refs + :save-display refs.screen +' + +test_tig + +assert_equals 'main.screen' < Initial commit + + + + + + +[main] 174877369ea7af366da2ebcedd63d7a00d8046ea - commit 1 of 1 100% +EOF + +assert_equals 'refs.screen' <