tag: make list exclude !<pattern>
PATCH 103/105 t3200 (branch): modernize style
In reply to Tom Grennan- Guard setup with test_expect_success
- Single-quoted, tab prefaced test blocks
--- t/t3200-branch.sh | 211 +++++++++++++++++++++++++++-------------------------- 1 files changed, 109 insertions(+), 102 deletions(-)
t/t3200-branch.sh +109 -102
@@ -7,15 +7,15 @@ test_description='git branch assorted tests' . ./test-lib.sh -test_expect_success \ - 'prepare a trivial repository' \ - 'echo Hello > A && +test_expect_success 'prepare a trivial repository' ' + echo Hello >A && git update-index --add A && git commit -m "Initial commit." && echo World >> A && git update-index --add A && git commit -m "Second commit." && - HEAD=$(git rev-parse --verify HEAD)' + HEAD=$(git rev-parse --verify HEAD) +' test_expect_success \ 'git branch --help should not have created a bogus branch' '
@@ -34,59 +34,59 @@ test_expect_success 'branch -h in broken repository' ' grep "[Uu]sage" broken/usage ' -test_expect_success \ - 'git branch abc should create a branch' \ - 'git branch abc && test_path_is_file .git/refs/heads/abc' +test_expect_success 'git branch abc should create a branch' ' + git branch abc && test_path_is_file .git/refs/heads/abc +' -test_expect_success \ - 'git branch a/b/c should create a branch' \ - 'git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c' +test_expect_success 'git branch a/b/c should create a branch' ' + git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c +' -cat >expect <<EOF +test_expect_success 'git branch -l d/e/f should create a branch and a log' ' + cat >expect <<-EOF $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master EOF -test_expect_success \ - 'git branch -l d/e/f should create a branch and a log' \ - 'GIT_COMMITTER_DATE="2005-05-26 23:30" \ + GIT_COMMITTER_DATE="2005-05-26 23:30" \ git branch -l d/e/f && test_path_is_file .git/refs/heads/d/e/f && test_path_is_file .git/logs/refs/heads/d/e/f && - test_cmp expect .git/logs/refs/heads/d/e/f' + test_cmp expect .git/logs/refs/heads/d/e/f +' -test_expect_success \ - 'git branch -d d/e/f should delete a branch and a log' \ - 'git branch -d d/e/f && +test_expect_success 'git branch -d d/e/f should delete a branch and a log' ' + git branch -d d/e/f && test_path_is_missing .git/refs/heads/d/e/f && - test_path_is_missing .git/logs/refs/heads/d/e/f' + test_path_is_missing .git/logs/refs/heads/d/e/f +' -test_expect_success \ - 'git branch j/k should work after branch j has been deleted' \ - 'git branch j && +test_expect_success 'git branch j/k should work after branch j has been deleted' ' + git branch j && git branch -d j && - git branch j/k' + git branch j/k +' -test_expect_success \ - 'git branch l should work after branch l/m has been deleted' \ - 'git branch l/m && +test_expect_success 'git branch l should work after branch l/m has been deleted' ' + git branch l/m && git branch -d l/m && - git branch l' + git branch l +' -test_expect_success \ - 'git branch -m dumps usage' \ - 'test_expect_code 129 git branch -m 2>err && - grep "[Uu]sage: git branch" err' +test_expect_success 'git branch -m dumps usage' ' + test_expect_code 129 git branch -m 2>err && + grep "[Uu]sage: git branch" err +' -test_expect_success \ - 'git branch -m m m/m should work' \ - 'git branch -l m && +test_expect_success 'git branch -m m m/m should work' ' + git branch -l m && git branch -m m m/m && - test_path_is_file .git/logs/refs/heads/m/m' + test_path_is_file .git/logs/refs/heads/m/m +' -test_expect_success \ - 'git branch -m n/n n should work' \ - 'git branch -l n/n && +test_expect_success 'git branch -m n/n n should work' ' + git branch -l n/n && git branch -m n/n n && - test_path_is_file .git/logs/refs/heads/n' + test_path_is_file .git/logs/refs/heads/n +' test_expect_success 'git branch -m o/o o should fail when o/p exists' ' git branch o/o &&
@@ -160,33 +160,30 @@ test_expect_success 'git branch --list -d t should fail' ' test_path_is_missing .git/refs/heads/t ' -mv .git/config .git/config-saved - test_expect_success 'git branch -m q q2 without config should succeed' ' + mv .git/config .git/config-saved && + test_when_finished mv .git/config-saved .git/config && git branch -m q q2 && git branch -m q2 q ' -mv .git/config-saved .git/config - +test_expect_success 'git branch -m s/s s should work when s/t is deleted' ' git config branch.s/s.dummy Hello - -test_expect_success \ - 'git branch -m s/s s should work when s/t is deleted' \ - 'git branch -l s/s && + git branch -l s/s && test_path_is_file .git/logs/refs/heads/s/s && git branch -l s/t && test_path_is_file .git/logs/refs/heads/s/t && git branch -d s/t && git branch -m s/s s && - test_path_is_file .git/logs/refs/heads/s' - -test_expect_success 'config information was renamed, too' \ - "test $(git config branch.s.dummy) = Hello && - test_must_fail git config branch.s/s/dummy" + test_path_is_file .git/logs/refs/heads/s +' -test_expect_success 'renaming a symref is not allowed' \ +test_expect_success 'config information was renamed, too' ' + test $(git config branch.s.dummy) = Hello && + test_must_fail git config branch.s/s/dummy ' + +test_expect_success 'renaming a symref is not allowed' ' git symbolic-ref refs/heads/master2 refs/heads/master && test_must_fail git branch -m master2 master3 && git symbolic-ref refs/heads/master2 &&
@@ -194,115 +191,125 @@ test_expect_success 'renaming a symref is not allowed' \ test_path_is_missing .git/refs/heads/master3 ' -test_expect_success SYMLINKS \ - 'git branch -m u v should fail when the reflog for u is a symlink' ' +test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' ' git branch -l u && mv .git/logs/refs/heads/u real-u && ln -s real-u .git/logs/refs/heads/u && test_must_fail git branch -m u v ' -test_expect_success 'test tracking setup via --track' \ - 'git config remote.local.url . && +test_expect_success 'test tracking setup via --track' ' + git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && (git show-ref -q refs/remotes/local/master || git fetch local) && git branch --track my1 local/master && test $(git config branch.my1.remote) = local && - test $(git config branch.my1.merge) = refs/heads/master' + test $(git config branch.my1.merge) = refs/heads/master +' -test_expect_success 'test tracking setup (non-wildcard, matching)' \ - 'git config remote.local.url . && - git config remote.local.fetch refs/heads/master:refs/remotes/local/master && +test_expect_success 'test tracking setup (non-wildcard, matching)' ' + git config remote.local.url . && + git config remote.local.fetch \ + refs/heads/master:refs/remotes/local/master && (git show-ref -q refs/remotes/local/master || git fetch local) && git branch --track my4 local/master && test $(git config branch.my4.remote) = local && - test $(git config branch.my4.merge) = refs/heads/master' + test $(git config branch.my4.merge) = refs/heads/master +' -test_expect_success 'test tracking setup (non-wildcard, not matching)' \ - 'git config remote.local.url . && +test_expect_success 'test tracking setup (non-wildcard, not matching)' ' + git config remote.local.url . && git config remote.local.fetch refs/heads/s:refs/remotes/local/s && (git show-ref -q refs/remotes/local/master || git fetch local) && git branch --track my5 local/master && ! test "$(git config branch.my5.remote)" = local && - ! test "$(git config branch.my5.merge)" = refs/heads/master' + ! test "$(git config branch.my5.merge)" = refs/heads/master +' -test_expect_success 'test tracking setup via config' \ - 'git config branch.autosetupmerge true && +test_expect_success 'test tracking setup via config' ' + git config branch.autosetupmerge true && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && (git show-ref -q refs/remotes/local/master || git fetch local) && git branch my3 local/master && test $(git config branch.my3.remote) = local && - test $(git config branch.my3.merge) = refs/heads/master' + test $(git config branch.my3.merge) = refs/heads/master +' -test_expect_success 'test overriding tracking setup via --no-track' \ - 'git config branch.autosetupmerge true && +test_expect_success 'test overriding tracking setup via --no-track' ' + git config branch.autosetupmerge true && git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && (git show-ref -q refs/remotes/local/master || git fetch local) && git branch --no-track my2 local/master && git config branch.autosetupmerge false && ! test "$(git config branch.my2.remote)" = local && - ! test "$(git config branch.my2.merge)" = refs/heads/master' + ! test "$(git config branch.my2.merge)" = refs/heads/master +' -test_expect_success 'no tracking without .fetch entries' \ - 'git config branch.autosetupmerge true && +test_expect_success 'no tracking without .fetch entries' ' + git config branch.autosetupmerge true && git branch my6 s && git config branch.automsetupmerge false && test -z "$(git config branch.my6.remote)" && - test -z "$(git config branch.my6.merge)"' + test -z "$(git config branch.my6.merge)" +' -test_expect_success 'test tracking setup via --track but deeper' \ - 'git config remote.local.url . && +test_expect_success 'test tracking setup via --track but deeper' ' + git config remote.local.url . && git config remote.local.fetch refs/heads/*:refs/remotes/local/* && (git show-ref -q refs/remotes/local/o/o || git fetch local) && git branch --track my7 local/o/o && test "$(git config branch.my7.remote)" = local && - test "$(git config branch.my7.merge)" = refs/heads/o/o' + test "$(git config branch.my7.merge)" = refs/heads/o/o +' -test_expect_success 'test deleting branch deletes branch config' \ - 'git branch -d my7 && +test_expect_success 'test deleting branch deletes branch config' ' + git branch -d my7 && test -z "$(git config branch.my7.remote)" && - test -z "$(git config branch.my7.merge)"' + test -z "$(git config branch.my7.merge)" +' -test_expect_success 'test deleting branch without config' \ - 'git branch my7 s && +test_expect_success 'test deleting branch without config' ' + git branch my7 s && sha1=$(git rev-parse my7 | cut -c 1-7) && echo "Deleted branch my7 (was $sha1)." >expect && git branch -d my7 >actual 2>&1 && - test_i18ncmp expect actual' + test_i18ncmp expect actual +' -test_expect_success 'test --track without .fetch entries' \ - 'git branch --track my8 && +test_expect_success 'test --track without .fetch entries' ' + git branch --track my8 && test "$(git config branch.my8.remote)" && - test "$(git config branch.my8.merge)"' + test "$(git config branch.my8.merge)" +' -test_expect_success \ - 'branch from non-branch HEAD w/autosetupmerge=always' \ - 'git config branch.autosetupmerge always && +test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' ' + git config branch.autosetupmerge always && git branch my9 HEAD^ && - git config branch.autosetupmerge false' + git config branch.autosetupmerge false +' -test_expect_success \ - 'branch from non-branch HEAD w/--track causes failure' \ - 'test_must_fail git branch --track my10 HEAD^' +test_expect_success 'branch from non-branch HEAD w/--track causes failure' ' + test_must_fail git branch --track my10 HEAD^ +' -test_expect_success \ - 'branch from tag w/--track causes failure' \ - 'git tag foobar && - test_must_fail git branch --track my11 foobar' +test_expect_success 'branch from tag w/--track causes failure' ' + git tag foobar && + test_must_fail git branch --track my11 foobar +' # Keep this test last, as it changes the current branch -cat >expect <<EOF +test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' ' + cat >expect <<-EOF $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master EOF -test_expect_success \ - 'git checkout -b g/h/i -l should create a branch and a log' \ - 'GIT_COMMITTER_DATE="2005-05-26 23:30" \ + GIT_COMMITTER_DATE="2005-05-26 23:30" \ git checkout -b g/h/i -l master && test_path_is_file .git/refs/heads/g/h/i && test_path_is_file .git/logs/refs/heads/g/h/i && - test_cmp expect .git/logs/refs/heads/g/h/i' + test_cmp expect .git/logs/refs/heads/g/h/i +' test_expect_success 'checkout -b makes reflog by default' ' git checkout master &&
Signature · 1 line
1.7.8
PATCH 104/105 t0040 (parse-options): modernize style
In reply to Tom Grennan- Guard setup with test_expect_success
--- t/t0040-parse-options.sh | 96 +++++++++++++++++++-------------------------- 1 files changed, 41 insertions(+), 55 deletions(-)
t/t0040-parse-options.sh +41 -55
@@ -7,7 +7,8 @@ test_description='our own option parser' . ./test-lib.sh -cat > expect << EOF +test_expect_success 'test help' ' + cat >expect <<-EOF && usage: test-parse-options <options> -b, --boolean get a boolean
@@ -23,7 +24,7 @@ usage: test-parse-options <options> String options -s, --string <string> - get a string + '' get a string --string2 <str> get another string --st <st> get another string (pervert ordering) -o <str> get another string
@@ -44,16 +45,14 @@ Standard options -q, --quiet be quiet EOF - -test_expect_success 'test help' ' + cp expect expect.err && test_must_fail test-parse-options -h > output 2> output.err && test ! -s output.err && test_cmp expect output ' -mv expect expect.err - -cat > expect << EOF +test_expect_success 'short options' ' + cat >expect <<-\EOF && boolean: 2 integer: 1729 timestamp: 0
@@ -64,15 +63,14 @@ quiet: no dry run: yes file: prefix/my.file EOF - -test_expect_success 'short options' ' test-parse-options -s123 -b -i 1729 -b -vv -n -F my.file \ > output 2> output.err && test_cmp expect output && test ! -s output.err ' -cat > expect << EOF +test_expect_success 'long options' ' + cat >expect <<-\EOF && boolean: 2 integer: 1729 timestamp: 0
@@ -83,8 +81,6 @@ quiet: no dry run: no file: prefix/fi.le EOF - -test_expect_success 'long options' ' test-parse-options --boolean --integer 1729 --boolean --string2=321 \ --verbose --verbose --no-dry-run --abbrev=10 --file fi.le\ --obsolete > output 2> output.err &&
@@ -101,7 +97,8 @@ test_expect_success 'missing required value' ' test $? = 129 ' -cat > expect << EOF +test_expect_success 'intermingled arguments' ' + cat >expect <<-\EOF && boolean: 1 integer: 13 timestamp: 0
@@ -115,15 +112,14 @@ arg 00: a1 arg 01: b1 arg 02: --boolean EOF - -test_expect_success 'intermingled arguments' ' test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \ > output 2> output.err && test ! -s output.err && test_cmp expect output ' -cat > expect << EOF +test_expect_success 'unambiguously abbreviated option' ' + cat >expect <<-\EOF && boolean: 0 integer: 2 timestamp: 0
@@ -134,8 +130,6 @@ quiet: no dry run: no file: (not set) EOF - -test_expect_success 'unambiguously abbreviated option' ' test-parse-options --int 2 --boolean --no-bo > output 2> output.err && test ! -s output.err && test_cmp expect output
@@ -152,7 +146,8 @@ test_expect_success 'ambiguously abbreviated option' ' test $? = 129 ' -cat > expect << EOF +test_expect_success 'non ambiguous option (after two options it abbreviates)' ' + cat >expect <<-\EOF && boolean: 0 integer: 0 timestamp: 0
@@ -163,24 +158,23 @@ quiet: no dry run: no file: (not set) EOF - -test_expect_success 'non ambiguous option (after two options it abbreviates)' ' test-parse-options --st 123 > output 2> output.err && test ! -s output.err && test_cmp expect output ' -cat > typo.err << EOF -error: did you mean \`--boolean\` (with two dashes ?) -EOF - test_expect_success 'detect possible typos' ' + cat >typo.err <<-\EOF && + error: did you mean `--boolean` (with two dashes ?) + EOF + >expect test_must_fail test-parse-options -boolean > output 2> output.err && - test ! -s output && - test_cmp typo.err output.err + test_cmp typo.err output.err && + test_cmp expect output ' -cat > expect <<EOF +test_expect_success 'keep some options as arguments' ' + cat >expect <<-\EOF && boolean: 0 integer: 0 timestamp: 0
@@ -192,14 +186,13 @@ dry run: no file: (not set) arg 00: --quux EOF - -test_expect_success 'keep some options as arguments' ' test-parse-options --quux > output 2> output.err && test ! -s output.err && test_cmp expect output ' -cat > expect <<EOF +test_expect_success 'OPT_DATE() and OPT_SET_PTR() work' ' + cat >expect <<-\EOF && boolean: 0 integer: 0 timestamp: 1
@@ -211,15 +204,14 @@ dry run: no file: (not set) arg 00: foo EOF - -test_expect_success 'OPT_DATE() and OPT_SET_PTR() work' ' - test-parse-options -t "1970-01-01 00:00:01 +0000" --default-string \ - foo -q > output 2> output.err && + test-parse-options -t "1970-01-01 00:00:01 +0000" \ + --default-string foo -q >output 2>output.err && test ! -s output.err && test_cmp expect output ' -cat > expect <<EOF +test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' ' + cat >expect <<-\EOF && Callback: "four", 0 boolean: 5 integer: 4
@@ -231,24 +223,22 @@ quiet: no dry run: no file: (not set) EOF - -test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' ' test-parse-options --length=four -b -4 > output 2> output.err && test ! -s output.err && test_cmp expect output ' -cat > expect <<EOF +test_expect_success 'OPT_CALLBACK() and callback errors work' ' + cat >expect <<-\EOF && Callback: "not set", 1 EOF - -test_expect_success 'OPT_CALLBACK() and callback errors work' ' test_must_fail test-parse-options --no-length > output 2> output.err && test_cmp expect output && test_cmp expect.err output.err ' -cat > expect <<EOF +test_expect_success 'OPT_BIT() and OPT_SET_INT() work' ' + cat >expect <<-\EOF && boolean: 1 integer: 23 timestamp: 0
@@ -259,8 +249,6 @@ quiet: no dry run: no file: (not set) EOF - -test_expect_success 'OPT_BIT() and OPT_SET_INT() work' ' test-parse-options --set23 -bbbbb --no-or4 > output 2> output.err && test ! -s output.err && test_cmp expect output
@@ -272,7 +260,8 @@ test_expect_success 'OPT_NEGBIT() and OPT_SET_INT() work' ' test_cmp expect output ' -cat > expect <<EOF +test_expect_success 'OPT_BIT() works' ' + cat >expect <<-\EOF && boolean: 6 integer: 0 timestamp: 0
@@ -283,8 +272,6 @@ quiet: no dry run: no file: (not set) EOF - -test_expect_success 'OPT_BIT() works' ' test-parse-options -bb --or4 > output 2> output.err && test ! -s output.err && test_cmp expect output
@@ -302,7 +289,9 @@ test_expect_success 'OPT_BOOLEAN() with PARSE_OPT_NODASH works' ' test_cmp expect output ' -cat > expect <<EOF + +test_expect_success 'OPT_NUMBER_CALLBACK() works' ' + cat >expect <<-\EOF && boolean: 0 integer: 12345 timestamp: 0
@@ -313,14 +302,13 @@ quiet: no dry run: no file: (not set) EOF - -test_expect_success 'OPT_NUMBER_CALLBACK() works' ' test-parse-options -12345 > output 2> output.err && test ! -s output.err && test_cmp expect output ' -cat >expect <<EOF +test_expect_success 'negation of OPT_NONEG flags is not ambiguous' ' + cat >expect <<-\EOF && boolean: 0 integer: 0 timestamp: 0
@@ -331,19 +319,17 @@ quiet: no dry run: no file: (not set) EOF - -test_expect_success 'negation of OPT_NONEG flags is not ambiguous' ' test-parse-options --no-ambig >output 2>output.err && test ! -s output.err && test_cmp expect output ' -cat >>expect <<'EOF' +test_expect_success '--list keeps list of strings' ' + cat >>expect <<-\EOF && list: foo list: bar list: baz EOF -test_expect_success '--list keeps list of strings' ' test-parse-options --list foo --list=bar --list=baz >output && test_cmp expect output '
Signature · 1 line
1.7.8
PATCH 105/105 t6300 (for-each-ref): modernize style
In reply to Tom Grennan- Guard setup with test_expect_success
- Unwound one loop to stay within the test_expect_success guard
--- t/t6300-for-each-ref.sh | 118 +++++++++++++++++++++++------------------------ 1 files changed, 58 insertions(+), 60 deletions(-)
t/t6300-for-each-ref.sh +58 -60
@@ -138,12 +138,13 @@ test_expect_success 'Check invalid format specifiers are errors' ' test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads ' -cat >expected <<\EOF +test_expect_success 'Check unformatted date fields output' ' + '" + cat >expected <<-EOF && 'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200' 'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200' EOF - -test_expect_success 'Check unformatted date fields output' ' + "' (git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads && git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual && test_cmp expected actual
@@ -171,84 +172,85 @@ test_expect_success 'Check format "relative" date fields output' ' git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual ' -cat >expected <<\EOF +test_expect_success 'Check format "short" date fields output' ' + '" + cat >expected <<-EOF 'refs/heads/master' '2006-07-03' '2006-07-03' 'refs/tags/testtag' '2006-07-03' EOF - -test_expect_success 'Check format "short" date fields output' ' + "' f=short && (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && test_cmp expected actual ' -cat >expected <<\EOF +test_expect_success 'Check format "local" date fields output' ' + '" + cat >expected <<-EOF 'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006' 'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006' EOF - -test_expect_success 'Check format "local" date fields output' ' - f=local && - (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && - git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && + "' + (git for-each-ref --shell --format="%(refname) %(committerdate:local) %(authordate:local)" refs/heads && + git for-each-ref --shell --format="%(refname) %(taggerdate:local)" refs/tags) >actual && test_cmp expected actual ' -cat >expected <<\EOF +test_expect_success 'Check format "iso8601" date fields output' ' + '" + cat >expected <<-EOF 'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200' 'refs/tags/testtag' '2006-07-03 17:18:45 +0200' EOF - -test_expect_success 'Check format "iso8601" date fields output' ' + "' f=iso8601 && (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && test_cmp expected actual ' -cat >expected <<\EOF +test_expect_success 'Check format "rfc2822" date fields output' ' + '" + cat >expected <<-EOF 'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200' 'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200' EOF - -test_expect_success 'Check format "rfc2822" date fields output' ' + "' f=rfc2822 && (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && test_cmp expected actual ' -cat >expected <<\EOF +test_expect_success 'Verify ascending sort' ' + cat >expected <<-EOF refs/heads/master refs/remotes/origin/master refs/tags/testtag EOF - -test_expect_success 'Verify ascending sort' ' git for-each-ref --format="%(refname)" --sort=refname >actual && test_cmp expected actual ' - -cat >expected <<\EOF +test_expect_success 'Verify descending sort' ' + cat >expected <<-EOF refs/tags/testtag refs/remotes/origin/master refs/heads/master EOF - -test_expect_success 'Verify descending sort' ' git for-each-ref --format="%(refname)" --sort=-refname >actual && test_cmp expected actual ' -cat >expected <<\EOF +test_expect_success 'Quoting style: shell' ' + '" + cat >expected <<-EOF 'refs/heads/master' 'refs/remotes/origin/master' 'refs/tags/testtag' EOF - -test_expect_success 'Quoting style: shell' ' + "' git for-each-ref --shell --format="%(refname)" >actual && test_cmp expected actual '
@@ -263,52 +265,51 @@ test_expect_success 'Quoting style: python' ' test_cmp expected actual ' -cat >expected <<\EOF +test_expect_success 'Quoting style: tcl' ' + cat >expected <<-EOF "refs/heads/master" "refs/remotes/origin/master" "refs/tags/testtag" EOF - -test_expect_success 'Quoting style: tcl' ' git for-each-ref --tcl --format="%(refname)" >actual && test_cmp expected actual ' -for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do - test_expect_success "more than one quoting style: $i" " - git for-each-ref $i 2>&1 | (read line && - case \$line in - \"error: more than one quoting style\"*) : happy;; - *) false - esac) - " -done - -cat >expected <<\EOF +test_expect_success 'more than one quoting styles' ' + cat >expected <<-EOF + error: more than one quoting style? + EOF + git for-each-ref --perl --shell 2>&1 | head -n 1 >actual && + test_cmp expected actual && + git for-each-ref -s --python 2>&1 | head -n 1 >actual && + test_cmp expected actual && + git for-each-ref --python --tcl 2>&1 | head -n 1 >actual && + test_cmp expected actual && + git for-each-ref --tcl --perl 2>&1 | head -n 1 >actual && + test_cmp expected actual +' +test_expect_success 'Check short refname format' ' + cat >expected <<-EOF master testtag EOF - -test_expect_success 'Check short refname format' ' (git for-each-ref --format="%(refname:short)" refs/heads && git for-each-ref --format="%(refname:short)" refs/tags) >actual && test_cmp expected actual ' -cat >expected <<EOF +test_expect_success 'Check short upstream format' ' + cat >expected <<-EOF origin/master EOF - -test_expect_success 'Check short upstream format' ' git for-each-ref --format="%(upstream:short)" refs/heads >actual && test_cmp expected actual ' -cat >expected <<EOF +test_expect_success 'Check short objectname format' ' + cat >expected <<-EOF 67a36f1 EOF - -test_expect_success 'Check short objectname format' ' git for-each-ref --format="%(objectname:short)" refs/heads >actual && test_cmp expected actual '
@@ -317,12 +318,11 @@ test_expect_success 'Check for invalid refname format' ' test_must_fail git for-each-ref --format="%(refname:INVALID)" ' -cat >expected <<\EOF +test_expect_success 'Check ambiguous head and tag refs (strict)' ' + cat >expected <<-EOF heads/master tags/master EOF - -test_expect_success 'Check ambiguous head and tag refs (strict)' ' git config --bool core.warnambiguousrefs true && git checkout -b newtag && echo "Using $datestamp" > one &&
@@ -334,23 +334,21 @@ test_expect_success 'Check ambiguous head and tag refs (strict)' ' test_cmp expected actual ' -cat >expected <<\EOF +test_expect_success 'Check ambiguous head and tag refs (loose)' ' + cat >expected <<-EOF heads/master master EOF - -test_expect_success 'Check ambiguous head and tag refs (loose)' ' git config --bool core.warnambiguousrefs false && git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual && test_cmp expected actual ' -cat >expected <<\EOF +test_expect_success 'Check ambiguous head and tag refs II (loose)' ' + cat >expected <<-EOF heads/ambiguous ambiguous EOF - -test_expect_success 'Check ambiguous head and tag refs II (loose)' ' git checkout master && git tag ambiguous testtag^0 && git branch ambiguous testtag^0 &&
@@ -369,7 +367,7 @@ test_expect_success 'an unusual tag with an incomplete line' ' ' test_expect_success 'create tag with subject and body content' ' - cat >>msg <<-\EOF && + cat >msg <<-\EOF && the subject line first body line
Signature · 1 line
1.7.8
Re: [PATCHv2 0/5] modernize test style
In reply to Tom GrennanQuoted 5 lines · Tom Grennan
t7004 (tag): modernize style
t5512 (ls-remote): modernize style
t3200 (branch): modernize style
t0040 (parse-options): modernize style
t6300 (for-each-ref): modernize style
Hmph.
We would want to keep/make the codebase uniformly conform to our style guide for longer term maintainability (this is not limited to the test scripts) but at the same time we would strongly want to avoid churning patches from interfering other patches that are still in flight that do "real work".
There are only two appropriate occasions for file-wide clean-up patches like these:
(1) The file has not been touched for quite some time, and it is not expected to be touched for some time to come; or
(2) You are going to do extensive work on the file for reasons other than clean-up, and nobody else is working or expected to work in the same area for some time to come (in other words, you _own_ the file), and your real work will be easier to review if it is done _after_ such a clean-up patch.
Let's see how active these five files are:
$ git diff --stat v1.7.9..pu -- t/t{7004,5512,3200,0040,6300}-*.sh
t/t0040-parse-options.sh | 60 ++++++++++++++++++++++-
t/t3200-branch.sh | 122 ++++++++++++++++++++++++++++++++++++++++++++--
t/t7004-tag.sh | 96 ++++++++++++++++++++++++++++++++++++
3 files changed, 272 insertions(+), 6 deletions(-)Given this, I do not want to take three of your 5 patches that touch these files at this point. Please hold onto them and wait until topics that touch these test scripts graduate to 'master', and then wait a bit more until some time passes without anybody touching them, before redoing the clean-up patches.
On the other hand, we can see that 5512 has been dormant for quite a while. Note that the latter diff is against 3 cycles ago:
$ git diff --stat v1.7.6..pu -- t/t{7004,5512,3200,0040,6300}-*.sh
t/t0040-parse-options.sh | 79 +++++++++++++++-
t/t3200-branch.sh | 236 +++++++++++++++++++++++++++++++++++++++++-----
t/t6300-for-each-ref.sh | 101 +++++++++++++++++++-
t/t7004-tag.sh | 128 +++++++++++++++++++------
4 files changed, 490 insertions(+), 54 deletions(-)so 5512 and possibly 6300 may be worth reviewing.
Thanks.
Re: [PATCHv2 0/5] modernize test style
Quoted 4 lines · Junio C Hamano
On the other hand, we can see that 5512 has been dormant for quite a while. Note that the latter diff is against 3 cycles ago:
Quoted 8 lines
$ git diff --stat v1.7.6..pu -- t/t{7004,5512,3200,0040,6300}-*.sh t/t0040-parse-options.sh | 79 +++++++++++++++- t/t3200-branch.sh | 236 +++++++++++++++++++++++++++++++++++++++++----- t/t6300-for-each-ref.sh | 101 +++++++++++++++++++- t/t7004-tag.sh | 128 +++++++++++++++++++------ 4 files changed, 490 insertions(+), 54 deletions(-)so 5512 and possibly 6300 may be worth reviewing.
Ack, I'll hold the others until each are quiescent for a few cycles.
Thanks.
TomG
PATCH v3 4/5 branch --exclude option
In reply to Tom GrennanExample,
$ ./git-branch -r --exclude \*HEAD origin/maint origin/master origin/next origin/pu origin/todo
--- Documentation/git-branch.txt | 7 ++++++- builtin/branch.c | 18 +++++++++++++----- t/t3200-branch.sh | 23 +++++++++++++++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-)
Documentation/git-branch.txt +6 -1
@@ -10,7 +10,8 @@ SYNOPSIS [verse] 'git branch' [--color[=<when>] | --no-color] [-r | -a] [--list] [-v [--abbrev=<length> | --no-abbrev]] - [(--merged | --no-merged | --contains) [<commit>]] [<pattern>...] + [(--merged | --no-merged | --contains) [<commit>]] + [--exclude <pattern>] [<pattern>...] 'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>] 'git branch' (-m | -M) [<oldbranch>] <newbranch> 'git branch' (-d | -D) [-r] <branchname>...
@@ -166,6 +167,10 @@ start-point is either a local or remote-tracking branch. --contains <commit>:: Only list branches which contain the specified commit. +--exclude <pattern>:: + Don't list branches matching the given pattern. This has + precedence over other match pattern arguments. + --merged [<commit>]:: Only list branches whose tips are reachable from the specified commit (HEAD if not specified).
builtin/branch.c +13 -5
@@ -243,6 +243,7 @@ struct ref_list {int index, alloc, maxwidth, verbose, abbrev;struct ref_item *list;struct commit_list *with_commit; +struct string_list *exclude;int kinds; };
@@ -300,7 +301,7 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,if ((kind & ref_list->kinds) ==0 )return 0 ; -if (!match_pattern (refname, cb->pattern,NULL ,0 )) +if (!match_pattern (refname, cb->pattern, ref_list->exclude,0 ))return 0 ; commit =NULL ;
@@ -498,7 +499,10 @@ static void show_detached(struct ref_list *ref_list) } } -static int print_ref_list (int kinds,int detached,int verbose,int abbrev,struct commit_list *with_commit,const char **pattern) +static int print_ref_list (int kinds,int detached,int verbose,int abbrev, +struct commit_list *with_commit, +struct string_list *exclude, +const char **pattern) {int i;struct append_ref_cb cb;
@@ -509,6 +513,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru ref_list.verbose = verbose; ref_list.abbrev = abbrev; ref_list.with_commit = with_commit; + ref_list.exclude = exclude;if (merge_filter !=NO_FILTER )init_revisions (&ref_list.revs,NULL ); cb.ref_list = &ref_list;
@@ -530,7 +535,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struqsort (ref_list.list, ref_list.index,sizeof (struct ref_item ), ref_cmp); detached = (detached && (kinds &REF_LOCAL_BRANCH )); -if (detached &&match_pattern ("HEAD" , pattern,NULL ,0 )) +if (detached &&match_pattern ("HEAD" , pattern, exclude,0 ))show_detached (&ref_list);for (i =0 ; i < ref_list.index; i++) {
@@ -665,7 +670,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)enum branch_track track;int kinds =REF_LOCAL_BRANCH ;struct commit_list *with_commit =NULL ; - +struct string_list exclude =STRING_LIST_INIT_NODUP ;struct option options[] = {OPT_GROUP ("Generic options" ), OPT__VERBOSE(&verbose,
@@ -689,6 +694,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)PARSE_OPT_HIDDEN |PARSE_OPT_LASTARG_DEFAULT , parse_opt_with_commit, (intptr_t )"HEAD" , }, +OPT_CALLBACK (0 ,"exclude" , &exclude,"pattern" , +"ignorepattern matching branches" , + parse_opt_string_list),OPT__ABBREV (&abbrev), OPT_GROUP("Specific git-branch actions:"),
@@ -753,7 +761,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)return delete_branches (argc, argv, delete >1 , kinds); else if (list) return print_ref_list(kinds, detached, verbose, abbrev, -with_commit ,argv ); + with_commit, &exclude, argv); else if (edit_description) {const char *branch_name;struct strbuf branch_ref =STRBUF_INIT ;
t/t3200-branch.sh +23 -0
@@ -160,6 +160,29 @@ test_expect_success 'git branch --list -d t should fail' ' test_path_is_missing .git/refs/heads/t ' +>expect +test_expect_success \ + 'git branch --list --exclude "t*" "t*" should be empty' ' + git branch ta && + git branch tb && + git branch --list --exclude "t*" "t*" > actual && + cmp expect actual +' + +cat >expect <<EOF + ta +EOF +test_expect_success \ + 'git branch --list --exclude "tb" "t*" should be "ta"' ' + git branch --list --exclude "tb" "t*" > actual && + cmp expect actual +' + +test_expect_success \ + 'git branch -d ta tb should succeed' ' + git branch -d ta tb +' + mv .git/config .git/config-saved test_expect_success 'git branch -m q q2 without config should succeed' '
Signature · 1 line
1.7.8
PATCH v3 5/5 for-each-ref --exclude option
In reply to Tom GrennanExample,
$ git for-each-ref --format="%(refname)" refs/remotes/origin refs/remotes/origin/HEAD refs/remotes/origin/maint refs/remotes/origin/master refs/remotes/origin/next refs/remotes/origin/pu refs/remotes/origin/todo $ ./git-for-each-ref --format="%(refname)" --exclude "*/HEAD" refs/remotes/origin refs/remotes/origin/maint refs/remotes/origin/master refs/remotes/origin/next refs/remotes/origin/pu refs/remotes/origin/todo
--- Documentation/git-for-each-ref.txt | 7 ++++++- builtin/for-each-ref.c | 8 +++++++- t/t6300-for-each-ref.sh | 11 +++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-)
Documentation/git-for-each-ref.txt +6 -1
@@ -9,7 +9,8 @@ SYNOPSIS -------- [verse] 'git for-each-ref' [--count=<count>] [--shell|--perl|--python|--tcl] - [(--sort=<key>)...] [--format=<format>] [<pattern>...] + [(--sort=<key>)...] [--format=<format>] + [--exclude=<pattern>] [<pattern>...] DESCRIPTION -----------
@@ -47,6 +48,10 @@ OPTIONS `xx`; for example `%00` interpolates to `\0` (NUL), `%09` to `\t` (TAB) and `%0a` to `\n` (LF). +--exclude <pattern>:: + Ignore refs matching the given pattern. This has precedence + over any other pattern match arguments. + <pattern>...:: If one or more patterns are given, only refs are shown that match against at least one pattern, either using fnmatch(3) or
builtin/for-each-ref.c +7 -1
@@ -91,6 +91,9 @@ static const char **used_atom;static cmp_type *used_atom_type;static int used_atom_cnt, sort_atom_limit, need_tagged, need_symref; +/* list of ref patterns and ref groups (i.e. foo/) to ignore */ +static struct string_list exclude =STRING_LIST_INIT_NODUP ; +/* * Used to parse format string and sort specifiers */
@@ -781,7 +784,7 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int fstruct refinfo *ref;int cnt; -if (!match_pattern (refname, cb->grab_pattern,NULL ,FNM_PATHNAME )) +if (!match_pattern (refname, cb->grab_pattern, &exclude,FNM_PATHNAME ))return 0 ;/*
@@ -985,6 +988,9 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)OPT_STRING (0 ,"format" , &format,"format" ,"format to use for the output" ),OPT_CALLBACK (0 ,"sort" , sort_tail,"key" ,"field name to sort on" , &opt_parse_sort), +OPT_CALLBACK (0 ,"exclude" , &exclude,"pattern" , +"ignore pattern matching refs" , + parse_opt_string_list), OPT_END(), };
t/t6300-for-each-ref.sh +11 -0
@@ -243,6 +243,17 @@ test_expect_success 'Verify descending sort' ' ' cat >expected <<\EOF +refs/tags/testtag +refs/heads/master +EOF + +test_expect_success 'Verify exclusion with sort' ' + git for-each-ref --format="%(refname)" --sort=-refname \ + --exclude "*origin*" >actual && + test_cmp expected actual +' + +cat >expected <<\EOF 'refs/heads/master' 'refs/remotes/origin/master' 'refs/tags/testtag'
Signature · 1 line
1.7.8
Quoted 7 lines · Junio C Hamano
Quoted 5 lines · Tom Grennan
The following series implements !<pattern> with: git-tag, git-branch, and git-for-each-ref.
This still requires Documentation and unit test updates but I think these are close to functionally complete.
Quoted 6 lines
Do we allow a refname whose pathname component begins with '!', by the way? If we do, how does a user look for a tag whose name is "!xyzzy"? "Naming your tag !xyzzy used to be allowed but it is now forbidden after this patch" is not an acceptable answer---it is called a regression. If the negation operator were "^" or something that we explicitly forbid from a refname, we wouldn't have such a problem.
According to git-check-ref-format(1), '!' are allowed in reference names. (Whether that was a good idea is another question, but now we have to support it.)
So using "^" would be an option. A problem is that the new meaning is not consistent with the use of "^" in rev-list, and therefore would (1) be confusing and (2) prevent the addition of a similar syntax in rev-list.
Currently,
git rev-list A B ^C
means "revisions reachable from A or B but not from C". (For simplicity assume that A, B, and C are literal reference names without wildcards.)
The proposal, amended to use "^" instead of "!", is that
git for-each-ref A B ^C
should mean "the reference names A and B but not C". Therefore, the command
git rev-list $(git for-each-ref A B ^C)
, which consistency suggests should do the same thing as the first command, would in fact be equivalent to
git rev-list A B
Moreover, it *would* be nice to have this kind of exclude-branch-name syntax in rev-parse. Many times I have wanted to type the equivalent of
gitk --all --not-branch=remotes/korg/*
That is, "show the commits starting at *all branches except for the specified branches*". This is different than "show *the commits starting at all branches* except for *the commits reachable from the specified branches*", because I want to see the *complete* history of the non-excluded branches. (Is there an easy way to do this now?) The proposed functionality is a step forward; I could type
gitk $(git for-each-ref !remotes/korg/*)
But it would be even nicer if this could be expressed directly in rev-parse.
In summary, I suggest we consider using a more verbose syntax for this new functionality (probably via one or more new options, for example --not-branch=PATTERN, --not-tag=PATTERN, and/or --not-ref=PATTERN) that cannot be confused with the existing syntax for excluding commits.
Michael
Signature · 3 lines
Michael Haggerty [email protected] http://softwareswirl.blogspot.com/
Quoted 10 lines · Michael Haggerty
The proposal, amended to use "^" instead of "!", is that
git for-each-ref A B ^C
should mean "the reference names A and B but not C". Therefore, the command
git rev-list $(git for-each-ref A B ^C), which consistency suggests should do the same thing as the first command,...
That is an utter rubbish that does not even deserve a response.
Your argument is like saying
git for-each-ref A
and
git for-each-ref $(git rev-parse A)
should somehow magically produce the same (or related) result. The for-each-ref command operates on refname patterns, while rev-list and rev-parse takes object names.
Quoted 19 lines · Junio C Hamano
Quoted 10 lines · Michael Haggerty
The proposal, amended to use "^" instead of "!", is that
git for-each-ref A B ^C
should mean "the reference names A and B but not C". Therefore, the command
git rev-list $(git for-each-ref A B ^C), which consistency suggests should do the same thing as the first command,...
That is an utter rubbish that does not even deserve a response.
Your argument is like saying
git for-each-ref A
Quoted 7 lines
and
git for-each-ref $(git rev-parse A)should somehow magically produce the same (or related) result. The for-each-ref command operates on refname patterns, while rev-list and rev-parse takes object names.
Of *course* they operate on different namespaces. But part of the way that revisions are selected using rev-list is by *selecting or excluding refnames* from which it should crawl. How long do you think it will be before somebody asks for rev-list to be able to crawl from a set of branches *except for those that match some pattern*? (Hint: I more or less asked for this feature in the "rubbish" email that you quoted.) At that point we will have to say one of the following:
"Your suggestion is utter rubbish; just type 'git rev-list $(git for-each-ref A B ^C)'."
This is an acceptable (though somewhat verbose) answer for the Unix command line; for msgit users it is useless, and it probably cannot be used in non-command-line scenarios like the gitk "edit view" dialog.
"Sure, but we have to invent yet another syntax because the one used by for-each-ref conflicts with the existing syntax of rev-list." This would be the standard git project practice of letting the UI accrete into an ever more incomprehensible mess.
That is why I suggest that we choose a new syntax *now* for for-each-ref (and "branch --list", "tag --list", etc) so that the same syntax can be used later in rev-list, rev-parse, etc.
Michael
Signature · 3 lines
Michael Haggerty [email protected] http://softwareswirl.blogspot.com/
Quoted 3 lines · Michael Haggerty
Of *course* they operate on different namespaces. But part of the way that revisions are selected using rev-list is by *selecting or excluding refnames* from which it should crawl.
I am appalled if that is truly the understanding of yours, after having taken more than a few patches from you to fairly core parts of Git.
"rev-list A ^B" does not say "include A and exclude B from which rev-list should crawl" AT ALL. We _actively_ crawl from both A and B. It is that what are reachable from B is painted in a color different from the color in which we paint what are reachable from A.
A better pair you could have mentioned would be for-each-ref vs rev-parse (not rev-list). What Tom wanted with "do not show the refs that match the pattern" he originally wanted to give to "tag --list" would be
for-each-ref A ^B
that is "show ref that matches A but do not show if it also matches B", while what you want to say is "I want to paint A in positive color and paint B in negative color, and I want to get a canonical notation to do so", it is spelled with rev-parse, not for-each-ref, like this:
rev-parse A ^B
In other words,
git rev-list $(git rev-parse A ^B)
would be the equivalent to "git rev-list A ^B".
Maybe you are troubled that there are multiple concepts of negation, which ultimately comes from the undeniable fact that for-each-ref and rev-parse operate on entities in different concept domain (refnames and objects)? And if we decide to use "^", then these two different concepts of negation are both expressed with the same operator "prefix ^", leading to confusion?
I am kind of sympathetic to that argument, and it might be a better idea to avoid using "^" as the negation for matching operator, in order to make it more apparent to the users that for-each-ref and rev-parse operate on different concepts. But at the same time, if you know these are distinct concepts, using the same "^" operator as a consistent way to express the "negation" that is applicable in each concept domain does make it easier for users as they gain experience. I tend to avoid making things too hard for experienced users for the sake of flattening the very early learning curve when possible, because nobody will stay novice forever.
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Michael Haggerty
Of *course* they operate on different namespaces. But part of the way that revisions are selected using rev-list is by *selecting or excluding refnames* from which it should crawl.
Quoted 7 lines
I am appalled if that is truly the understanding of yours, after having taken more than a few patches from you to fairly core parts of Git.
"rev-list A ^B" does not say "include A and exclude B from which rev-list should crawl" AT ALL. We _actively_ crawl from both A and B. It is that what are reachable from B is painted in a color different from the color in which we paint what are reachable from A.
Please read my emails more carefully before insulting me.
It is perfectly clear to me that there are two types of exclusion that we are talking about. And *both* of them are (or should be) relevant to rev-parse.
Take the following repository with three branches:
o---o---o---o A
\ \
\ o---o C
\
o---o BIf I do "git rev-list A B ^C" then I get the commits marked "*" in the following diagram
o---o---o---* A
\ \
\ o---o C
\
*---* BBy excluding C I have necessarily excluded a part of the history of A and B.
If we assume that the proposed feature is implemented and I do "git rev-list $(git for-each-ref --format='%(refname)' A B ^C)", then I get something different:
*---*---*---* A
\ \
\ o---o C
\
*---* BI argue that this is a useful selection. For example, maybe I want to remove the clutter of branch C from my view, but I still want to see the *whole* history of branches A and B. The middle selection doesn't do it.
Obviously this is not really necessary if there are only three branches, but if there are dozens, and if A, B, and C are patterns rather than literal branch names, then it can be very convenient.
For example, suppose I want to see the status of all of my submissions in your repository in the context of your main branches plus my local branches. It would be great to be able to type
gitk --with-branch='refs/heads/*' \
--with-branch='remotes/gitster/*' \
--without-branch='remotes/gitster/*/**' \
--with-branch='remotes/gitster/mh/*'I don't know of a way to do that now.
Quoted 4 lines
A better pair you could have mentioned would be for-each-ref vs rev-parse (not rev-list). What Tom wanted with "do not show the refs that match the pattern" he originally wanted to give to "tag --list" would be
Quoted 8 lines
for-each-ref A ^B
that is "show ref that matches A but do not show if it also matches B", while what you want to say is "I want to paint A in positive color and paint B in negative color, and I want to get a canonical notation to do so", it is spelled with rev-parse, not for-each-ref, like this:
rev-parse A ^B
That's not what I want; see above.
Quoted 4 lines
In other words,
git rev-list $(git rev-parse A ^B)
Quoted 8 lines
would be the equivalent to "git rev-list A ^B".
Maybe you are troubled that there are multiple concepts of negation, which ultimately comes from the undeniable fact that for-each-ref and rev-parse operate on entities in different concept domain (refnames and objects)? And if we decide to use "^", then these two different concepts of negation are both expressed with the same operator "prefix ^", leading to confusion?
Not only that, but also that both concepts of negation are interesting and useful within "git rev-list", and therefore we should make them *combinable*.
To be very explicit, I advocate:
1. Implement an explicit syntax for "do not include references matching this pattern in a list of references". Implement this syntax in for-each-ref; something like
--with-ref=PATTERN / --without-ref=PATTERN
--with-branch=PATTERN / --without-branch=PATTERN
--with-tag=PATTERN / --without-tag=PATTERN
--with-remote=PATTERN / --without-remote=PATTERNThe point of having multiple with/without pairs would be that the first would match full refnames explicitly (i.e., the pattern would usually start with "refs/"), whereas the other pairs would implicitly prepend "refs/heads/", "refs/tags/", or "refs/remotes/", respectively, to the pattern for convenience. There should also be an "--all" option that is equivalent to "--with-ref=**".
The output from for-each-ref would essentially be a *list of positive references* matching the criteria. In other words, "--without-branch=foo" would cause "refs/heads/foo" to be *excluded* from the output altogether, *not* included as "^refs/heads/foo".
The order of the options should be significant, with the last matching pattern winning.
2. The pattern matching of refnames should be like fnmatch, with the addition of "**" as a wildcard meaning "any characters, including '/'".
3. Other reference-listing commands should take the same options as appropriate; for example, "git branch --list" would take --with(out)?-branch and --with(out)?-remote (and maybe --with(out)?-ref); "git tag --list" would take --with(out)?-tag (and maybe --with(out)?-ref), etc.
4. The *exact same options* should be added to rev-list, and would effectively be expanded into a list of positive references; e.g.,
git rev-list --with-branch=A --with-branch=B --without-branch=C
would be equivalent to
git rev-list $(git for-each-ref --format='%(refname)'
--with-branch=A --with-branch=B --without-branch=C)
If A, B, and C happen to be branch names rather than patterns, the above would be equivalent to
git rev-list refs/heads/A refs/heads/B
Note that this *differs* (in a useful way!) from
git rev-list refs/heads/A refs/heads/B --not refs/heads/C
or
git rev-list refs/heads/A refs/heads/B ^refs/heads/C
which are useful in other scenarios and whose meanings we would of course retain.
If "--not" is used in git-rev-list, it would demarcate groups of options that are passed separately to for-each-ref; for example,
git rev-list --all --with-branch=A --without-branch=B \
--not --with-branch=C --without-branch=Dwould be equivalent to
git rev-list $(git for-each-ref --format='%(refname)' --all
--with-branch=A --without-branch=B)\
--not $(git for-each-ref --format='%(refname)'--with-branch=C --without-branch=D)
Michael
Signature · 3 lines
Michael Haggerty [email protected] http://softwareswirl.blogspot.com/
Quoted 25 lines · Michael Haggerty
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Michael Haggerty
Of *course* they operate on different namespaces. But part of the way that revisions are selected using rev-list is by *selecting or excluding refnames* from which it should crawl.
Quoted 7 lines
I am appalled if that is truly the understanding of yours, after having taken more than a few patches from you to fairly core parts of Git.
"rev-list A ^B" does not say "include A and exclude B from which rev-list should crawl" AT ALL. We _actively_ crawl from both A and B. It is that what are reachable from B is painted in a color different from the color in which we paint what are reachable from A.
Please read my emails more carefully before insulting me.
...
o---o---o---* A\ \ \ o---o C \ *---* B... vs ...
Quoted 7 lines
*---*---*---* A
\ \ \ o---o C \ *---* BI argue that this is a useful selection.
Then why were you so against the addition of "negation" to for-each-ref?
If you want "I want histories reaching A and B", just say "rev-list A B", without adding useless "er, I do not want histories reaching C in the output, but I do not want commits reachable from C to be excluded from the output either" by mentioning C. Learn to shut your mouth and not talk about irrelevant "C" in such a case, and you will do just fine.
Especially, re-read your first message where you said that between
git rev-list A B ^C
and
git rev-list $(git for-each-ref A B ^C)
"consistency suggests should do the same". Should the consistency also suggest that
git rev-list $(git rev-parse A B ^C)
do the same? That is a total bullshit that can only come from somebody who does not understand the distinction between pattern matching in refnames vs set operation over commit DAG.
Having said all that, if your argument against using "^" as negation for for-each-ref *were* with something like this from the beginning:
git rev-list --all --exclude-refs=refs/tags/v\*
it would have been very different. I would wholeheartedly buy the consistency argument that says
git for-each-ref --exclude-refs=refs/tags/v\*
ought to give all refs (only because for-each-ref "all" is implied) except for the tagged tips, and
git log --all --exclude-refs=refs/tags/v\*
should be the notation to produce consistently the same result as
git log $(git for-each-ref --format='%(objectname)' --exclude-refs=refs/tags/v\*)
but if we used "^" as negated match in for-each-ref argument, we would close the door to give such consistency to log family of commands later.
But that wasn't what you said. Why should I get accused of not guessing what you meant to say but you clearly didn't, and in addition blamed for insulting merely for pointing out the idiocy in what you said?
No. *YOU* go back and re-read your message more carefully.
Quoted 33 lines · Junio C Hamano
Quoted 31 lines · Michael Haggerty
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Michael Haggerty
Of *course* they operate on different namespaces. But part of the way that revisions are selected using rev-list is by *selecting or excluding refnames* from which it should crawl.
Quoted 7 lines
I am appalled if that is truly the understanding of yours, after having taken more than a few patches from you to fairly core parts of Git.
"rev-list A ^B" does not say "include A and exclude B from which rev-list should crawl" AT ALL. We _actively_ crawl from both A and B. It is that what are reachable from B is painted in a color different from the color in which we paint what are reachable from A.
Please read my emails more carefully before insulting me.
...
o---o---o---* A\ \ \ o---o C \ *---* B... vs ...
*---*---*---* A
\ \ \ o---o C \ *---* B
Quoted 3 lines
Quoted 1 line
I argue that this is a useful selection.
Then why were you so against the addition of "negation" to for-each-ref?
I'm not against it. I just think it should be spelled differently.
Quoted 5 lines
If you want "I want histories reaching A and B", just say "rev-list A B", without adding useless "er, I do not want histories reaching C in the output, but I do not want commits reachable from C to be excluded from the output either" by mentioning C. Learn to shut your mouth and not talk about irrelevant "C" in such a case, and you will do just fine.
That's fine if we're talking about single references. But it does not generalize to patterns, like my example
gitk --with-branch='refs/heads/*' \
--with-branch='remotes/gitster/*' \
--without-branch='remotes/gitster/*/**' \
--with-branch='remotes/gitster/mh/*'If these options were supported, I could store this set of arguments as a "view" in gitk and have it load automatically. It would continue to work even as you add and delete branches from your repository. Listing the branches explicitly would be fragile. Currently I would have to write a script wrapper around gitk that invokes multiple git commands and filters the results using grep or something. (At least I don't know a better way.) Even if for-each-ref were taught to exclude branches, I don't believe it is possible to use arbitrary shell commands to build a gitk view.
Quoted 9 lines
Especially, re-read your first message where you said that between
git rev-list A B ^C
and
git rev-list $(git for-each-ref A B ^C)"consistency suggests should do the same".
I should have connected the dots better: consistency suggests they should do the same, but they obviously cannot. Moreover, it would be nice if the two types of exclusion could be combined in single commands, in which case consistency is mandatory. Therefore, let's spell the for-each-ref option another way that *can* be made consistent across commands.
Quoted 13 lines
Having said all that, if your argument against using "^" as negation for for-each-ref *were* with something like this from the beginning:
git rev-list --all --exclude-refs=refs/tags/v\*it would have been very different. I would wholeheartedly buy the consistency argument that says
git for-each-ref --exclude-refs=refs/tags/v\*ought to give all refs (only because for-each-ref "all" is implied) except for the tagged tips, and
Quoted 8 lines
git log --all --exclude-refs=refs/tags/v\*should be the notation to produce consistently the same result as
git log $(git for-each-ref --format='%(objectname)' --exclude-refs=refs/tags/v\*)but if we used "^" as negated match in for-each-ref argument, we would close the door to give such consistency to log family of commands later.
That *has* been exactly my argument from the beginning [1]. I cautiously hope that we are now talking about the same thing, even if it is not yet clear whether we agree on a conclusion.
I think this would be an interesting project, but I won't have time to work on it in the near future. My first priority is to get the hierarchical-refs patches rebased on top of the removal of extra refs and do some more rationalization in that area.
Michael
[1] I don't see where anything I've written is inconsistent with your phrasing of the argument. But fine, let's just be happy that the miscommunication now seems to be cleared up.
Signature · 3 lines
Michael Haggerty [email protected] http://softwareswirl.blogspot.com/
Quoted 15 lines · Michael Haggerty
Quoted 15 lines
Having said all that, if your argument against using "^" as negation for for-each-ref *were* with something like this from the beginning:
git rev-list --all --exclude-refs=refs/tags/v\*it would have been very different. I would wholeheartedly buy the consistency argument that says
git for-each-ref --exclude-refs=refs/tags/v\*ought to give all refs (only because for-each-ref "all" is implied) except for the tagged tips, and
git log --all --exclude-refs=refs/tags/v\*
Quoted 8 lines
Quoted 6 lines
should be the notation to produce consistently the same result as
git log $(git for-each-ref --format='%(objectname)' --exclude-refs=refs/tags/v\*)but if we used "^" as negated match in for-each-ref argument, we would close the door to give such consistency to log family of commands later.
That *has* been exactly my argument from the beginning [1].
Well, if the only thing you say is "rev-list A B ^C" and you are expecting that your reader to substitute A with any dashed option like --all, --not or --stdin, I would have to say you are expecting too much. I wouldn't even think of substituting A with $(git for-each-ref refs/heads/) in such an example.
Quoted 2 lines
I cautiously hope that we are now talking about the same thing, even if it is not yet clear whether we agree on a conclusion.
I think we are on the same page now. Given that we seem to have settled for the recent "find in the paths that pathspec matches, but exclude matches from paths that match these patterns" topic by Albert Yale to tentatively use separate --exclude [*1*] command line option instead of mixing the negatives to the usual list of positives at the UI level, it appears to me that the most sensible way forward would be to expose the negative match to the UI level is to introduce a similar --exclude-refs on the command line.
That would eventually allow us to say something like [*2*]:
git log --all \
--exclude-refs=refs/heads/experimental/* \
--exclude-paths=compat/ \
--since=30.days \
-- '*.c'to ask for recent changes to all C sources outside the compat/ area for everything except for the experimental topics.
[Footnote]
*1* It might be better to spell this as --exclude-paths, though, if we are going to call this other exclude-refs-by-pattern --exclude-refs. The longer names would not bother us with the help of parse-options, and the commands that need to support both, namely the commands in the log family, need to allow users to be explicit which exclusion they want anyway, and having --exclude vs --exclude-refs as options that work on different dimensions look asymmetric.
*2* "something like" includes using a convenience short-hand on this command line such as "--branches --exclude-branches=experimental/*" instead of "--all --exclude-refs=...", but I consider that is icing on the cake after the first step to define the overall structure settles, so I would prefer not to go into the tangential details.
Quoted 3 lines · Junio C Hamano
... Same
for 1c, which I highly suspect will introduce regression without looking at the code (for-each-ref is prefix-match only), ...
This part needs correction. for-each-ref matches the command line arguments differently from branch --list and tag --list in two important ways.
(1) It allows (not "only" which was a mistake in my earlier message) prefix matching, e.g. "for-each-ref refs/heads/", in addition to fnmatch(); and
(2) The fnmatch() call is made with FNM_PATHMAME, which "branch --list" and "tag --list" does not use.
Strictly speaking, therefore, if you make all three commands to use the same matching logic, there is no way to avoid regression. If you choose to use fnmatch() without FNM_PATHNAME, then for-each-ref suddenly starts matching wildcards across name hierarchy boundary '/' for a pattern that does not match today, e.g. "git for-each-ref 'refs/heads/*'" was a good way to grab only the integration branches while excluding individual topic branches such as refs/heads/tg/tag-points-at, but this technique can no longer be used for such a purpose, which is an unpleasant regression.
I personally think that it was an annoying UI mistake that we let branch and tag call fnmatch without FNM_PATHNAME, but we cannot fix it lightly, either. People who use hierchical branch names (e.g. maint-1.0/$topic, maint-2.0/$topic, and feature-2.0/$topic) may already be used to list all the topics on the maintenance tracks with "branch --list 'maint*'", and we need to keep "branch --list" and "tag --list" working as they expect.
One possible way forward (now I am talking about a longer term solution) would be to introduce
refname_match_pattern(const char *refname,
const char **pattern, unsigned flags);
where flags can tell the implementation if FNM_PATHNAME should be used, and if prefix matching should be attempted, so that the three commands share the single same matching function while still retaining their current behaviour in the initial round. Inside the implementation, we would use good old fnmatch(), with or without FNM_PATHNAME, depending on the flags the caller passes.
In a future versions, we may want to have "branch/tag --list" also ask for FNM_PATHNAME (this *is* a backward incompatible change, so it needs to be performed across major version boundary, with backward compatibility configurations, deprecation warnings and whole nine yards). Under the new match function, today's "branch --list 'maint*'" needs to be spelled as "branch --list 'maint*/*'" or something. The prefix matching is probably safer to enable by default without causing big regression hassle if we limit the prefix match to only patterns that end with an explicit slash, as users already *know* today's "branch --list tg/" would not match anything (because the pattern does not even match a brahch 'tg', so it is unlikely they are using it and expecting only 'tg' to match), which means that is an unlikely input we can safely give new meaning to match anything under tg/ hierarchy.
Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Junio C Hamano
... Same
for 1c, which I highly suspect will introduce regression without looking at the code (for-each-ref is prefix-match only), ...
OK I'll study this further and run through t6300-for-each-ref.sh I see it has a bunch of errors.
I think there are similar issues using match_pattern() with show-branch and ls-remote.
Thanks,
Quoted 55 lines
This part needs correction. for-each-ref matches the command line arguments differently from branch --list and tag --list in two important ways.
(1) It allows (not "only" which was a mistake in my earlier message) prefix matching, e.g. "for-each-ref refs/heads/", in addition to
fnmatch(); and(2) The
fnmatch()call is made withFNM_PATHMAME, which "branch --list" and "tag --list" does not use.Strictly speaking, therefore, if you make all three commands to use the same matching logic, there is no way to avoid regression. If you choose to use
fnmatch()withoutFNM_PATHNAME, then for-each-ref suddenly starts matching wildcards across name hierarchy boundary '/' for a pattern that does not match today, e.g. "git for-each-ref 'refs/heads/*'" was a good way to grab only the integration branches while excluding individual topic branches such as refs/heads/tg/tag-points-at, but this technique can no longer be used for such a purpose, which is an unpleasant regression.I personally think that it was an annoying UI mistake that we let branch and tag call fnmatch without
FNM_PATHNAME, but we cannot fix it lightly, either. People who use hierchical branch names (e.g. maint-1.0/$topic, maint-2.0/$topic, and feature-2.0/$topic) may already be used to list all the topics on the maintenance tracks with "branch --list 'maint*'", and we need to keep "branch --list" and "tag --list" working as they expect.One possible way forward (now I am talking about a longer term solution) would be to introduce
refname_match_pattern(const char *refname,
const char **pattern,
unsigned flags);where flags can tell the implementation if
FNM_PATHNAMEshould be used, and if prefix matching should be attempted, so that the three commands share the single same matching function while still retaining their current behaviour in the initial round. Inside the implementation, we would use good oldfnmatch(), with or withoutFNM_PATHNAME, depending on the flags the caller passes.In a future versions, we may want to have "branch/tag --list" also ask for
FNM_PATHNAME(this *is* a backward incompatible change, so it needs to be performed across major version boundary, with backward compatibility configurations, deprecation warnings and whole nine yards). Under the new match function, today's "branch --list 'maint*'" needs to be spelled as "branch --list 'maint*/*'" or something. The prefix matching is probably safer to enable by default without causing big regression hassle if we limit the prefix match to only patterns that end with an explicit slash, as users already *know* today's "branch --list tg/" would not match anything (because the pattern does not even match a brahch 'tg', so it is unlikely they are using it and expecting only 'tg' to match), which means that is an unlikely input we can safely give new meaning to match anything under tg/ hierarchy.
Quoted 6 lines · Junio C Hamano
In a future versions, we may want to have "branch/tag --list" also ask for
FNM_PATHNAME(this *is* a backward incompatible change, so it needs to be performed across major version boundary, with backward compatibility configurations, deprecation warnings and whole nine yards). Under the new match function, today's "branch --list 'maint*'" needs to be spelled as "branch --list 'maint*/*'" or something.
Or "branch --list 'maint**'
Signature · 1 line
Jakub Narebski
Quoted 10 lines · Jakub Narebski
Quoted 6 lines · Junio C Hamano
In a future versions, we may want to have "branch/tag --list" also ask for
FNM_PATHNAME(this *is* a backward incompatible change, so it needs to be performed across major version boundary, with backward compatibility configurations, deprecation warnings and whole nine yards). Under the new match function, today's "branch --list 'maint*'" needs to be spelled as "branch --list 'maint*/*'" or something.Or "branch --list 'maint**'
That is one of the things covered by "or something", and I deliberately left it like so because all the good things that can happen "In future version" are irrelevant at the present _unless_ the required first step you omitted from your quote is not done properly, and I didn't want to invite people to derail the discussion into such a tangent that does not yet have any value.
Please don't.
Quoted 8 lines · Jakub Narebski
Quoted 6 lines · Junio C Hamano
In a future versions, we may want to have "branch/tag --list" also ask for
FNM_PATHNAME(this *is* a backward incompatible change, so it needs to be performed across major version boundary, with backward compatibility configurations, deprecation warnings and whole nine yards). Under the new match function, today's "branch --list 'maint*'" needs to be spelled as "branch --list 'maint*/*'" or something.
One of the reasons I proposed pathspec is to avoid another set of matching syntax in addition to gitattr, gitignore and pathspec, Pathspec magic makes it extensible, FNM_PATHNAME be set that way.
Quoted 1 line
Or "branch --list 'maint**'
But this comes up a few times already on gitignore discussions. We have fnmatch.c in compat for Windows. Someone just needs to step up and implement "**". It would also a nice thing to add to pathspec syntax, if we can forget the backward compatibility nightmare.
Signature · 1 line
Duy