From 6645838845c523952f60a855f8c646d49e59cee0 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 21 Nov 2016 15:18:05 +0100 Subject: [PATCH 1/3] rebase -i: highlight problems with core.commentchar The interactive rebase does not currently play well with core.commentchar. Let's add some tests to highlight those problems that will be fixed in the remainder of the series. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t0030-stripspace.sh | 9 +++++++++ t/t3404-rebase-interactive.sh | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/t/t0030-stripspace.sh b/t/t0030-stripspace.sh index 29e91d861c..c1f6411eb2 100755 --- a/t/t0030-stripspace.sh +++ b/t/t0030-stripspace.sh @@ -432,6 +432,15 @@ test_expect_success '-c with changed comment char' ' test_cmp expect actual ' +test_expect_failure '-c with comment char defined in .git/config' ' + test_config core.commentchar = && + printf "= foo\n" >expect && + printf "foo" | ( + mkdir sub && cd sub && git stripspace -c + ) >actual && + test_cmp expect actual +' + test_expect_success 'avoid SP-HT sequence in commented line' ' printf "#\tone\n#\n# two\n" >expect && printf "\tone\n\ntwo\n" | git stripspace -c >actual && diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index d6d65a3a94..d941f0a69f 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -983,6 +983,17 @@ test_expect_success 'rebase -i respects core.commentchar' ' test B = $(git cat-file commit HEAD^ | sed -ne \$p) ' +test_expect_failure 'rebase -i respects core.commentchar=auto' ' + test_config core.commentchar auto && + write_script copy-edit-script.sh <<-\EOF && + cp "$1" edit-script + EOF + test_set_editor "$(pwd)/copy-edit-script.sh" && + test_when_finished "git rebase --abort || :" && + git rebase -i HEAD^ && + test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)" +' + test_expect_success 'rebase -i, with and specified as :/quuxery' ' test_when_finished "git branch -D torebase" && git checkout -b torebase branch1 && From 92068ae8bf5711b683a0dbeef75d76f56ead5590 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 21 Nov 2016 15:18:24 +0100 Subject: [PATCH 2/3] stripspace: respect repository config The way "git stripspace" reads the configuration was not quite kosher, in that the code forgot to probe for a possibly existing repository (note: stripspace is designed to be usable outside the repository as well). It read .git/config only when it was run from the top-level of the working tree by accident. A recent change b9605bc4f2 ("config: only read .git/config from configured repos", 2016-09-12) stopped reading the repository-local configuration file ".git/config" unless the repository discovery process is done, so that .git/config is never read even when run from the top-level, exposing the old bug more. When rebasing interactively with a commentChar defined in the current repository's config, the help text at the bottom of the edit script potentially used an incorrect comment character. This was not only funny-looking, but also resulted in tons of warnings like this one: Warning: the command isn't recognized in the following line - # Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin/stripspace.c | 4 +++- t/t0030-stripspace.sh | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/builtin/stripspace.c b/builtin/stripspace.c index 15e716ef43..1e62a008cb 100644 --- a/builtin/stripspace.c +++ b/builtin/stripspace.c @@ -44,8 +44,10 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix) if (argc) usage_with_options(stripspace_usage, options); - if (mode == STRIP_COMMENTS || mode == COMMENT_LINES) + if (mode == STRIP_COMMENTS || mode == COMMENT_LINES) { + setup_git_directory_gently(NULL); git_config(git_default_config, NULL); + } if (strbuf_read(&buf, 0, 1024) < 0) die_errno("could not read the input"); diff --git a/t/t0030-stripspace.sh b/t/t0030-stripspace.sh index c1f6411eb2..bbf3e39e3d 100755 --- a/t/t0030-stripspace.sh +++ b/t/t0030-stripspace.sh @@ -432,7 +432,7 @@ test_expect_success '-c with changed comment char' ' test_cmp expect actual ' -test_expect_failure '-c with comment char defined in .git/config' ' +test_expect_success '-c with comment char defined in .git/config' ' test_config core.commentchar = && printf "= foo\n" >expect && printf "foo" | ( From 882cd23777f8984e433e0c0addae5e9d70de75e8 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 21 Nov 2016 15:18:29 +0100 Subject: [PATCH 3/3] rebase -i: handle core.commentChar=auto When 84c9dc2 (commit: allow core.commentChar=auto for character auto selection, 2014-05-17) extended the core.commentChar functionality to allow for the value 'auto', it forgot that rebase -i was already taught to handle core.commentChar, and in turn forgot to let rebase -i handle that new value gracefully. Reported by Taufiq Hoven. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-rebase--interactive.sh | 13 +++++++++++-- t/t3404-rebase-interactive.sh | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 655ebaa471..c167bc36b3 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -93,8 +93,17 @@ eval ' GIT_CHERRY_PICK_HELP="$resolvemsg" export GIT_CHERRY_PICK_HELP -comment_char=$(git config --get core.commentchar 2>/dev/null | cut -c1) -: ${comment_char:=#} +comment_char=$(git config --get core.commentchar 2>/dev/null) +case "$comment_char" in +'' | auto) + comment_char="#" + ;; +?) + ;; +*) + comment_char=$(echo "$comment_char" | cut -c1) + ;; +esac warn () { printf '%s\n' "$*" >&2 diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index d941f0a69f..5d0a7dca9d 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -983,7 +983,7 @@ test_expect_success 'rebase -i respects core.commentchar' ' test B = $(git cat-file commit HEAD^ | sed -ne \$p) ' -test_expect_failure 'rebase -i respects core.commentchar=auto' ' +test_expect_success 'rebase -i respects core.commentchar=auto' ' test_config core.commentchar auto && write_script copy-edit-script.sh <<-\EOF && cp "$1" edit-script