log: add %S option (like --source) to log --format
Make it possible to write for example git log --format="%H,%S" where the %S at the end is a new placeholder that prints out the ref (tag/branch) for each commit. Using %d might seem like an alternative but it only shows the ref for the last commit in the branch. Signed-off-by: Issac Trotts <issactrotts@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
ecbdaf0899
commit
ad6f028f06
@ -621,4 +621,54 @@ test_expect_success 'trailer parsing not fooled by --- line' '
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'set up %S tests' '
|
||||
git checkout --orphan source-a &&
|
||||
test_commit one &&
|
||||
test_commit two &&
|
||||
git checkout -b source-b HEAD^ &&
|
||||
test_commit three
|
||||
'
|
||||
|
||||
test_expect_success 'log --format=%S paints branch names' '
|
||||
cat >expect <<-\EOF &&
|
||||
source-b
|
||||
source-a
|
||||
source-b
|
||||
EOF
|
||||
git log --format=%S source-a source-b >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'log --format=%S paints tag names' '
|
||||
git tag -m tagged source-tag &&
|
||||
cat >expect <<-\EOF &&
|
||||
source-tag
|
||||
source-a
|
||||
source-tag
|
||||
EOF
|
||||
git log --format=%S source-tag source-a >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'log --format=%S paints symmetric ranges' '
|
||||
cat >expect <<-\EOF &&
|
||||
source-b
|
||||
source-a
|
||||
EOF
|
||||
git log --format=%S source-a...source-b >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success '%S in git log --format works with other placeholders (part 1)' '
|
||||
git log --format="source-b %h" source-b >expect &&
|
||||
git log --format="%S %h" source-b >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success '%S in git log --format works with other placeholders (part 2)' '
|
||||
git log --format="%h source-b" source-b >expect &&
|
||||
git log --format="%h %S" source-b >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_done
|
||||
|
@ -185,6 +185,10 @@ test_expect_success 'basic colors' '
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success '%S is not a placeholder for rev-list yet' '
|
||||
git rev-list --format="%S" -1 master | grep "%S"
|
||||
'
|
||||
|
||||
test_expect_success 'advanced colors' '
|
||||
cat >expect <<-EOF &&
|
||||
commit $head2
|
||||
|
Reference in New Issue
Block a user