]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge: add a --signoff flag
authorŁukasz Gryglicki <lukaszgryglicki@o2.pl>
Tue, 4 Jul 2017 09:33:06 +0000 (09:33 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Jul 2017 19:11:47 +0000 (12:11 -0700)
Some projects require every commit, even merges, to be signed off
[*1*].  Because "git merge" does not have a "--signoff" option like
"git commit" does, the user needs to add one manually when the
command presents an editor to describe the merge, or later use "git
commit --amend --signoff".

Help developers of these projects by teaching "--signoff" option to
"git merge".

*1* https://public-inbox.org/git/CAHv71zK5SqbwrBFX=a8-DY9H3KT4FEyMgv__p2gZzNr0WUAPUw@mail.gmail.com/T/#u

Requested-by: Dan Kohn <dan@linuxfoundation.org>
Signed-off-by: Łukasz Gryglicki <lukaszgryglicki@o2.pl>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-merge.txt
builtin/merge.c
t/t7614-merge-signoff.sh [new file with mode: 0755]

index 04fdd8cf086db6413a01421c306a80c9583f7fa4..6b308ab6d0b52b8962da63a8bc268cdf3f7ed227 100644 (file)
@@ -64,6 +64,14 @@ OPTIONS
 -------
 include::merge-options.txt[]
 
+--signoff::
+       Add Signed-off-by line by the committer at the end of the commit
+       log message.  The meaning of a signoff depends on the project,
+       but it typically certifies that committer has
+       the rights to submit this work under the same license and
+       agrees to a Developer Certificate of Origin
+       (see http://developercertificate.org/ for more information).
+
 -S[<keyid>]::
 --gpg-sign[=<keyid>]::
        GPG-sign the resulting merge commit. The `keyid` argument is
index 900bafdb45d0b28ab5497cfd251535266fc92be5..78c36e9bf353b53a1a0dad38a4804e6f3b2de980 100644 (file)
@@ -70,6 +70,7 @@ static int continue_current_merge;
 static int allow_unrelated_histories;
 static int show_progress = -1;
 static int default_to_upstream = 1;
+static int signoff;
 static const char *sign_commit;
 
 static struct strategy all_strategy[] = {
@@ -233,6 +234,7 @@ static struct option builtin_merge_options[] = {
        { OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key-id"),
          N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
        OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")),
+       OPT_BOOL(0, "signoff", &signoff, N_("add Signed-off-by:")),
        OPT_END()
 };
 
@@ -763,6 +765,8 @@ static void prepare_to_commit(struct commit_list *remoteheads)
        strbuf_addch(&msg, '\n');
        if (0 < option_edit)
                strbuf_commented_addf(&msg, _(merge_editor_comment), comment_line_char);
+       if (signoff)
+               append_signoff(&msg, ignore_non_trailer(msg.buf, msg.len), 0);
        write_file_buf(git_path_merge_msg(), msg.buf, msg.len);
        if (run_commit_hook(0 < option_edit, get_index_file(), "prepare-commit-msg",
                            git_path_merge_msg(), "merge", NULL))
diff --git a/t/t7614-merge-signoff.sh b/t/t7614-merge-signoff.sh
new file mode 100755 (executable)
index 0000000..c1b8446
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+test_description='git merge --signoff
+
+This test runs git merge --signoff and makes sure that it works.
+'
+
+. ./test-lib.sh
+
+# Setup test files
+test_setup() {
+       # Expected commit message after merge --signoff
+       cat >expected-signed <<EOF &&
+Merge branch 'master' into other-branch
+
+Signed-off-by: $(git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/")
+EOF
+
+       # Expected commit message after merge without --signoff (or with --no-signoff)
+       cat >expected-unsigned <<EOF &&
+Merge branch 'master' into other-branch
+EOF
+
+       # Initial commit and feature branch to merge master into it.
+       git commit --allow-empty -m "Initial empty commit" &&
+       git checkout -b other-branch &&
+       test_commit other-branch file1 1
+}
+
+# Setup repository, files & feature branch
+# This step must be run if You want to test 2,3 or 4
+# Order of 2,3,4 is not important, but 1 must be run before
+# For example `-r 1,4` or `-r 1,4,2 -v` etc
+# But not `-r 2` or `-r 4,3,2,1`
+test_expect_success 'setup' '
+       test_setup
+'
+
+# Test with --signoff flag
+test_expect_success 'git merge --signoff adds a sign-off line' '
+       git checkout master &&
+       test_commit master-branch-2 file2 2 &&
+       git checkout other-branch &&
+       git merge master --signoff --no-edit &&
+       git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+       test_cmp expected-signed actual
+'
+
+# Test without --signoff flag
+test_expect_success 'git merge does not add a sign-off line' '
+       git checkout master &&
+       test_commit master-branch-3 file3 3 &&
+       git checkout other-branch &&
+       git merge master --no-edit &&
+       git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+       test_cmp expected-unsigned actual
+'
+
+# Test for --no-signoff flag
+test_expect_success 'git merge --no-signoff flag cancels --signoff flag' '
+       git checkout master &&
+       test_commit master-branch-4 file4 4 &&
+       git checkout other-branch &&
+       git merge master --no-edit --signoff --no-signoff &&
+       git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
+       test_cmp expected-unsigned actual
+'
+
+test_done