From 786a028b12eb6eefb157097a80aba85da184567f Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Mon, 4 Jan 2016 20:06:00 -0500 Subject: [PATCH] Do not expand `--all` when parsing %(revargs) Passing `--all` to `git-rev-parse --revs-only` will expand it to all revs in the repository, which causes Tig to exit with the error: tig: No revisions match the given argument. if a revision is deleted or added and the view is reloaded. In addition, it also causes problems in repositories with many revs. Fixes #442 and fixes #462. --- NEWS.adoc | 1 + src/display.c | 8 +++----- src/tig.c | 11 +++++++++++ test/main/all-arg-test | 41 +++++++++++++++++++++++++++++++++++++++++ test/tools/libtest.sh | 11 +++++++++-- 5 files changed, 65 insertions(+), 7 deletions(-) create mode 100755 test/main/all-arg-test diff --git a/NEWS.adoc b/NEWS.adoc index 9c402df..b5c79be 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -40,6 +40,7 @@ Bug fixes: - Add currently checked out branch to `%(branch)` (GH #416) - Fix segfault when hitting return in empty file search (GH #464) - Remove separator on horizontal split when switching from vertical split + - Do not expand `--all` when parsing `%(revargs)` (GH #442, #462) tig-2.1.1 --------- diff --git a/src/display.c b/src/display.c index 335e3fe..86c5c37 100644 --- a/src/display.c +++ b/src/display.c @@ -53,7 +53,7 @@ open_external_viewer(const char *argv[], const char *dir, bool silent, bool conf { bool ok; - if (silent) { + if (silent || is_script_executing()) { ok = io_run_bg(argv, dir); } else { @@ -62,10 +62,8 @@ open_external_viewer(const char *argv[], const char *dir, bool silent, bool conf if (confirm || !ok) { if (!ok && *notice) fprintf(stderr, "%s", notice); - if (!is_script_executing()) { - fprintf(stderr, "Press Enter to continue"); - getc(opt_tty); - } + fprintf(stderr, "Press Enter to continue"); + getc(opt_tty); } } diff --git a/src/tig.c b/src/tig.c index 6d237da..c1f827d 100644 --- a/src/tig.c +++ b/src/tig.c @@ -420,6 +420,17 @@ filter_options(const char *argv[], bool rev_parse) opt_cmdline_args = flags; } + for (next = flags_pos = 0; argv[next]; next++) { + const char *arg = argv[next]; + + if (!strcmp(arg, "--all")) + argv_append(&opt_rev_args, arg); + else + argv[flags_pos++] = arg; + } + + argv[flags_pos] = NULL; + filter_rev_parse(&opt_rev_args, "--symbolic", "--revs-only", argv); } diff --git a/test/main/all-arg-test b/test/main/all-arg-test new file mode 100755 index 0000000..454ff4f --- /dev/null +++ b/test/main/all-arg-test @@ -0,0 +1,41 @@ +#!/bin/sh + +. libtest.sh +. libgit.sh +. "$source_dir/util.sh" + +export LINES=16 + +steps ' + :set line-graphics = ascii + :exec !assert-var "%(revargs)" == "--all" + :exec !git branch -D mp/feature + :save-display final.screen +' + +in_work_dir create_repo_from_tgz "$base_dir/files/refs-repo.tgz" + +test_tig --all + +assert_vars + +assert_equals stderr < Commit 10 B +2010-03-04 04:09 A. U. Thor * Commit 10 A +2010-02-23 15:46 Max Power * Commit 9 E +2010-02-15 03:24 Jørgen Thygesen Brahe * Commit 9 D +2010-02-06 15:02 作者 * Commit 9 C +2010-01-29 02:40 René Lévesque * Commit 9 B +2010-01-20 14:18 A. U. Thor * Commit 9 A +2010-01-12 01:56 Max Power * Commit 8 E +2010-01-03 13:33 Jørgen Thygesen Brahe * Commit 8 D +2009-12-26 01:11 作者 * [r1.1.2] [r1.1.x] Commit 8 C +[main] 042f71a7592228ae84cbb3642c2666dcd35aa527 - commit 1 of 51 27% +EOF diff --git a/test/tools/libtest.sh b/test/tools/libtest.sh index 72ef5a0..bc7e6e2 100644 --- a/test/tools/libtest.sh +++ b/test/tools/libtest.sh @@ -251,8 +251,15 @@ executable 'assert-var' <> "$expected_var_file" -echo "\$3" >> "$HOME/$vars_file" +while [ \$# -gt 1 ]; do + arg="\$1"; shift + + case "\$arg" in + ==) break ;; + *) echo "\$arg" >> "$HOME/$vars_file" ;; + esac +done +echo "\$@" >> "$expected_var_file" EOF assert_vars() -- 2.11.4.GIT