]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t7502-commit-porcelain.sh
Merge branch 'en/ort-perf-batch-9'
[thirdparty/git.git] / t / t7502-commit-porcelain.sh
index 6396897cc81804be174db6e37ccc7a8af8d648f1..38a532d81ccd060d7c42e1a3f413bdfeccf4715b 100755 (executable)
@@ -38,6 +38,16 @@ check_summary_oneline() {
        test_cmp exp act
 }
 
+trailer_commit_base () {
+       echo "fun" >>file &&
+       git add file &&
+       git commit -s --trailer "Signed-off-by=C1 E1 " \
+               --trailer "Helped-by:C2 E2 " \
+               --trailer "Reported-by=C3 E3" \
+               --trailer "Mentored-by:C4 E4" \
+               -m "hello"
+}
+
 test_expect_success 'output summary format' '
 
        echo new >file1 &&
@@ -154,6 +164,308 @@ test_expect_success 'sign off' '
 
 '
 
+test_expect_success 'commit --trailer with "="' '
+       trailer_commit_base &&
+       cat >expected <<-\EOF &&
+       hello
+
+       Signed-off-by: C O Mitter <committer@example.com>
+       Signed-off-by: C1 E1
+       Helped-by: C2 E2
+       Reported-by: C3 E3
+       Mentored-by: C4 E4
+       EOF
+       git cat-file commit HEAD >commit.msg &&
+       sed -e "1,/^\$/d" commit.msg >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'commit --trailer with -c and "replace" as ifexists' '
+       trailer_commit_base &&
+       cat >expected <<-\EOF &&
+       hello
+
+       Signed-off-by: C O Mitter <committer@example.com>
+       Signed-off-by: C1 E1
+       Reported-by: C3 E3
+       Mentored-by: C4 E4
+       Helped-by: C3 E3
+       EOF
+       git -c trailer.ifexists="replace" \
+               commit --trailer "Mentored-by: C4 E4" \
+                --trailer "Helped-by: C3 E3" \
+               --amend &&
+       git cat-file commit HEAD >commit.msg &&
+       sed -e "1,/^\$/d"  commit.msg >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'commit --trailer with -c and "add" as ifexists' '
+       trailer_commit_base &&
+       cat >expected <<-\EOF &&
+       hello
+
+       Signed-off-by: C O Mitter <committer@example.com>
+       Signed-off-by: C1 E1
+       Helped-by: C2 E2
+       Reported-by: C3 E3
+       Mentored-by: C4 E4
+       Reported-by: C3 E3
+       Mentored-by: C4 E4
+       EOF
+       git -c trailer.ifexists="add" \
+               commit --trailer "Reported-by: C3 E3" \
+               --trailer "Mentored-by: C4 E4" \
+               --amend &&
+       git cat-file commit HEAD >commit.msg &&
+       sed -e "1,/^\$/d"  commit.msg >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'commit --trailer with -c and "donothing" as ifexists' '
+       trailer_commit_base &&
+       cat >expected <<-\EOF &&
+       hello
+
+       Signed-off-by: C O Mitter <committer@example.com>
+       Signed-off-by: C1 E1
+       Helped-by: C2 E2
+       Reported-by: C3 E3
+       Mentored-by: C4 E4
+       Reviewed-by: C6 E6
+       EOF
+       git -c trailer.ifexists="donothing" \
+               commit --trailer "Mentored-by: C5 E5" \
+               --trailer "Reviewed-by: C6 E6" \
+               --amend &&
+       git cat-file commit HEAD >commit.msg &&
+       sed -e "1,/^\$/d"  commit.msg >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'commit --trailer with -c and "addIfDifferent" as ifexists' '
+       trailer_commit_base &&
+       cat >expected <<-\EOF &&
+       hello
+
+       Signed-off-by: C O Mitter <committer@example.com>
+       Signed-off-by: C1 E1
+       Helped-by: C2 E2
+       Reported-by: C3 E3
+       Mentored-by: C4 E4
+       Mentored-by: C5 E5
+       EOF
+       git -c trailer.ifexists="addIfDifferent" \
+               commit --trailer "Reported-by: C3 E3" \
+               --trailer "Mentored-by: C5 E5" \
+               --amend &&
+       git cat-file commit HEAD >commit.msg &&
+       sed -e "1,/^\$/d"  commit.msg >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'commit --trailer with -c and "addIfDifferentNeighbor" as ifexists' '
+       trailer_commit_base &&
+       cat >expected <<-\EOF &&
+       hello
+
+       Signed-off-by: C O Mitter <committer@example.com>
+       Signed-off-by: C1 E1
+       Helped-by: C2 E2
+       Reported-by: C3 E3
+       Mentored-by: C4 E4
+       Reported-by: C3 E3
+       EOF
+       git -c trailer.ifexists="addIfDifferentNeighbor" \
+               commit --trailer "Mentored-by: C4 E4" \
+               --trailer "Reported-by: C3 E3" \
+               --amend &&
+       git cat-file commit HEAD >commit.msg &&
+       sed -e "1,/^\$/d"  commit.msg >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'commit --trailer with -c and "end" as where' '
+       trailer_commit_base &&
+       cat >expected <<-\EOF &&
+       hello
+
+       Signed-off-by: C O Mitter <committer@example.com>
+       Signed-off-by: C1 E1
+       Helped-by: C2 E2
+       Reported-by: C3 E3
+       Mentored-by: C4 E4
+       Reported-by: C3 E3
+       Mentored-by: C4 E4
+       EOF
+       git -c trailer.where="end" \
+               commit --trailer "Reported-by: C3 E3" \
+               --trailer "Mentored-by: C4 E4" \
+               --amend &&
+       git cat-file commit HEAD >commit.msg &&
+       sed -e "1,/^\$/d" commit.msg >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'commit --trailer with -c and "start" as where' '
+       trailer_commit_base &&
+       cat >expected <<-\EOF &&
+       hello
+
+       Signed-off-by: C1 E1
+       Signed-off-by: C O Mitter <committer@example.com>
+       Signed-off-by: C1 E1
+       Helped-by: C2 E2
+       Reported-by: C3 E3
+       Mentored-by: C4 E4
+       EOF
+       git -c trailer.where="start" \
+               commit --trailer "Signed-off-by: C O Mitter <committer@example.com>" \
+               --trailer "Signed-off-by: C1 E1" \
+               --amend &&
+       git cat-file commit HEAD >commit.msg &&
+       sed -e "1,/^\$/d" commit.msg >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'commit --trailer with -c and "after" as where' '
+       trailer_commit_base &&
+       cat >expected <<-\EOF &&
+       hello
+
+       Signed-off-by: C O Mitter <committer@example.com>
+       Signed-off-by: C1 E1
+       Helped-by: C2 E2
+       Reported-by: C3 E3
+       Mentored-by: C4 E4
+       Mentored-by: C5 E5
+       EOF
+       git -c trailer.where="after" \
+               commit --trailer "Mentored-by: C4 E4" \
+               --trailer "Mentored-by: C5 E5" \
+               --amend &&
+       git cat-file commit HEAD >commit.msg &&
+       sed -e "1,/^\$/d" commit.msg >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'commit --trailer with -c and "before" as where' '
+       trailer_commit_base &&
+       cat >expected <<-\EOF &&
+       hello
+
+       Signed-off-by: C O Mitter <committer@example.com>
+       Signed-off-by: C1 E1
+       Helped-by: C2 E2
+       Reported-by: C3 E3
+       Mentored-by: C2 E2
+       Mentored-by: C3 E3
+       Mentored-by: C4 E4
+       EOF
+       git -c trailer.where="before" \
+               commit --trailer "Mentored-by: C3 E3" \
+               --trailer "Mentored-by: C2 E2" \
+               --amend &&
+       git cat-file commit HEAD >commit.msg &&
+       sed -e "1,/^\$/d" commit.msg >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'commit --trailer with -c and "donothing" as ifmissing' '
+       trailer_commit_base &&
+       cat >expected <<-\EOF &&
+       hello
+
+       Signed-off-by: C O Mitter <committer@example.com>
+       Signed-off-by: C1 E1
+       Helped-by: C2 E2
+       Reported-by: C3 E3
+       Mentored-by: C4 E4
+       Helped-by: C5 E5
+       EOF
+       git -c trailer.ifmissing="donothing" \
+               commit --trailer "Helped-by: C5 E5" \
+               --trailer "Based-by: C6 E6" \
+               --amend &&
+       git cat-file commit HEAD >commit.msg &&
+       sed -e "1,/^\$/d" commit.msg >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'commit --trailer with -c and "add" as ifmissing' '
+       trailer_commit_base &&
+       cat >expected <<-\EOF &&
+       hello
+
+       Signed-off-by: C O Mitter <committer@example.com>
+       Signed-off-by: C1 E1
+       Helped-by: C2 E2
+       Reported-by: C3 E3
+       Mentored-by: C4 E4
+       Helped-by: C5 E5
+       Based-by: C6 E6
+       EOF
+       git -c trailer.ifmissing="add" \
+               commit --trailer "Helped-by: C5 E5" \
+               --trailer "Based-by: C6 E6" \
+               --amend &&
+       git cat-file commit HEAD >commit.msg &&
+       sed -e "1,/^\$/d" commit.msg >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'commit --trailer with -c ack.key ' '
+       echo "fun" >>file1 &&
+       git add file1 &&
+       cat >expected <<-\EOF &&
+               hello
+
+               Acked-by: Peff
+       EOF
+       git -c trailer.ack.key="Acked-by" \
+               commit --trailer "ack = Peff" -m "hello" &&
+       git cat-file commit HEAD >commit.msg &&
+       sed -e "1,/^\$/d" commit.msg >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'commit --trailer with -c and ":=#" as separators' '
+       echo "fun" >>file1 &&
+       git add file1 &&
+       cat >expected <<-\EOF &&
+               I hate bug
+
+               Bug #42
+       EOF
+       git -c trailer.separators=":=#" \
+               -c trailer.bug.key="Bug #" \
+               commit --trailer "bug = 42" -m "I hate bug" &&
+       git cat-file commit HEAD >commit.msg &&
+       sed -e "1,/^\$/d" commit.msg >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'commit --trailer with -c and command' '
+       trailer_commit_base &&
+       cat >expected <<-\EOF &&
+       hello
+
+       Signed-off-by: C O Mitter <committer@example.com>
+       Signed-off-by: C1 E1
+       Helped-by: C2 E2
+       Mentored-by: C4 E4
+       Reported-by: A U Thor <author@example.com>
+       EOF
+       git -c trailer.report.key="Reported-by: " \
+               -c trailer.report.ifexists="replace" \
+               -c trailer.report.command="NAME=\"\$ARG\"; test -n \"\$NAME\" && \
+               git log --author=\"\$NAME\" -1 --format=\"format:%aN <%aE>\" || true" \
+               commit --trailer "report = author" --amend &&
+       git cat-file commit HEAD >commit.msg &&
+       sed -e "1,/^\$/d" commit.msg >actual &&
+       test_cmp expected actual
+'
+
 test_expect_success 'multiple -m' '
 
        >negative &&