[PATCH] Add a --signoff option to cherry-pick/revert.
From: Florian Ragwitz <hidden>
Date: 2016-06-15 22:44:34
Subsystem:
documentation, the rest · Maintainers:
Jonathan Corbet, Linus Torvalds
Also modify documentation and tests to reflect this change. Signed-off-by: Florian Ragwitz <redacted> --- Documentation/git-cherry-pick.txt | 3 +++ Documentation/git-revert.txt | 3 +++ builtin-revert.c | 25 ++++++++++++++++++++----- t/t3501-revert-cherry-pick.sh | 19 +++++++++++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt
index f0beb41..ec8bd50 100644
--- a/Documentation/git-cherry-pick.txt
+++ b/Documentation/git-cherry-pick.txt@@ -39,6 +39,9 @@ OPTIONS development branch), adding this information can be useful. +-s|--signoff:: + Add Signed-off-by line at the end of the commit message. + -r:: It used to be that the command defaulted to do `-x` described above, and `-r` was to disable it. Now the
diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt
index 93e20f7..a35a376 100644
--- a/Documentation/git-revert.txt
+++ b/Documentation/git-revert.txt@@ -27,6 +27,9 @@ OPTIONS message prior to committing the revert. This is the default if you run the command from a terminal. +-s|--signoff:: + Add Signed-off-by line at the end of the commit message. + -m parent-number|--mainline parent-number:: Usually you cannot revert a merge because you do not know which side of the merge should be considered the mainline. This
diff --git a/builtin-revert.c b/builtin-revert.c
index 607a2f0..ccf591c 100644
--- a/builtin-revert.c
+++ b/builtin-revert.c@@ -33,7 +33,7 @@ static const char * const cherry_pick_usage[] = { NULL }; -static int edit, no_replay, no_commit, mainline; +static int edit, no_replay, no_commit, mainline, signoff; static enum { REVERT, CHERRY_PICK } action; static struct commit *commit;
@@ -53,6 +53,7 @@ static void parse_args(int argc, const char **argv) OPT_BOOLEAN('e', "edit", &edit, "edit the commit message"), OPT_BOOLEAN('x', NULL, &no_replay, "append commit name when cherry-picking"), OPT_BOOLEAN('r', NULL, &noop, "no-op (backward compatibility)"), + OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"), OPT_INTEGER('m', "mainline", &mainline, "parent number"), OPT_END(), };
@@ -404,10 +405,24 @@ static int revert_or_cherry_pick(int argc, const char **argv) */ if (!no_commit) { - if (edit) - return execl_git_cmd("commit", "-n", NULL); - else - return execl_git_cmd("commit", "-n", "-F", defmsg, NULL); + const char *args[6]; + int i = 0; + + args[i++] = "commit"; + args[i++] = "-n"; + + if (!edit) { + args[i++] = "-F"; + args[i++] = defmsg; + } + + if (signoff) { + args[i++] = "-s"; + } + + args[i] = NULL; + + return execv_git_cmd(args); } free(reencoded_message);
diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh
index 6da2128..2f74f74 100755
--- a/t/t3501-revert-cherry-pick.sh
+++ b/t/t3501-revert-cherry-pick.sh@@ -50,6 +50,25 @@ test_expect_success 'cherry-pick after renaming branch' ' ' +test_expect_success 'cherry-pick signoff' ' + + git checkout rename2 && + git cherry-pick -s added && + test -f opos && + git cat-file commit HEAD | sed "1,/^$/d" > output && + grep Signed-off-by output +' + +test_expect_success 'revert signoff' ' + + git checkout rename1 && + git revert -s added && + test -f spoo && + git cat-file commit HEAD | sed "1,/^$/d" > output && + grep Signed-off-by output + +' + test_expect_success 'revert after renaming branch' ' git checkout rename1 &&
--
1.5.5.1