request-pull: write to file option
cover request-pull: write to file option
Currently, git request-pull only outputs PR message to stdout. Users wished to send the message have to use shell redirection to file. Add the option to write it to user-specified file.
Bagas Sanjaya (3):
request-pull: introduce display_message() function
request-pull: add -o/--output option
request-pull: document -o/--output
Documentation/git-request-pull.txt | 16 +++++- git-request-pull.sh | 81 +++++++++++++++++++++--------- t/t5150-request-pull.sh | 13 +++++ 3 files changed, 83 insertions(+), 27 deletions(-)
base-commit: cefe983a320c03d7843ac78e73bd513a27806845
Signature · 1 line
An old man doll... just what I always wanted! - Clara
PATCH 1/3 request-pull: introduce display_message() function
Move displaying PR message logic into display_message. While at it, use local variable $format and $dashline to shorten argument typing to git show.
--- git-request-pull.sh | 57 ++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 22 deletions(-)
git-request-pull.sh +35 -22
@@ -136,37 +136,50 @@ fi url=$(git ls-remote --get-url "$url") -git show -s --format='The following changes since commit %H: +display_message() { + local format + local dash_line + + dash_line="----------------------------------------------------------------" + format='The following changes since commit %H: %s (%ci) are available in the Git repository at: -' $merge_base && -echo " $url $pretty_remote" && -git show -s --format=' -for you to fetch changes up to %H: +' + + git show -s --format="$format" $merge_base && + echo " $url $pretty_remote" && + format='for you to fetch changes up to %H: %s (%ci) +' + git show -s --format=" +$format +$dash_line" $headrev && -----------------------------------------------------------------' $headrev && + if test $(git cat-file -t "$head") = tag + then + git cat-file tag "$head" | + sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p + echo + echo "$dash_line" + fi && -if test $(git cat-file -t "$head") = tag -then - git cat-file tag "$head" | - sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p - echo - echo "----------------------------------------------------------------" -fi && + if test -n "$branch_name" + then + echo "(from the branch description for $branch_name local branch)" + echo + git config "branch.$branch_name.description" + echo "$dash_line" + fi && -if test -n "$branch_name" -then - echo "(from the branch description for $branch_name local branch)" - echo - git config "branch.$branch_name.description" - echo "----------------------------------------------------------------" -fi && + git shortlog ^$baserev $headrev && + git diff -M --stat --summary $patch $merge_base..$headrev +} -git shortlog ^$baserev $headrev && -git diff -M --stat --summary $patch $merge_base..$headrev || status=1 +message=$(display_message) || status=1 + +echo "$message" exit $status
Signature · 1 line
An old man doll... just what I always wanted! - Clara
PATCH 2/3 request-pull: add -o/--output option
In reply to Bagas SanjayaAdd -o option (and long dash counterpart --option), which allow users to write pull request message to the specified file.
--- git-request-pull.sh | 28 +++++++++++++++++++++++----- t/t5150-request-pull.sh | 13 +++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-)
git-request-pull.sh +23 -5
@@ -7,10 +7,12 @@ SUBDIRECTORY_OK='Yes' OPTIONS_KEEPDASHDASH= OPTIONS_STUCKLONG= -OPTIONS_SPEC='git request-pull [options] start url [end] +OPTIONS_SPEC="\ +git request-pull [options] start url [end] -- -p show patch text as well -' +p show patch text as well +o,output= output pull request to the specified file +" . git-sh-setup
@@ -18,11 +20,16 @@ GIT_PAGER= export GIT_PAGER patch= -while case "$#" in 0) break ;; esac +out= +while test $# != 0 do case "$1" in -p) patch=-p ;; + -o|--output) + case "$2" in '') usage ;; esac + out="$2" + shift ;; --) shift; break ;; -*)
@@ -180,6 +187,17 @@ $dash_line" $headrev && message=$(display_message) || status=1 -echo "$message" +if test $status -ne 0 +then + echo "There's an error when outputting message, exiting" + exit $status +fi + +if test -n "$out" +then + echo "$message" > "$out" +else + echo "$message" +fi exit $status
t/t5150-request-pull.sh +13 -0
@@ -168,6 +168,19 @@ test_expect_success 'pull request after push' ' ' +test_expect_success 'pull request output with -o' ' + + rm -fr downstream.git && + git init --bare downstream.git && + ( + cd local && + git checkout initial && + git merge --ff-only main && + git push origin main:for-upstream && + git request-pull -o ../request initial origin main:for-upstream + ) +' + test_expect_success 'request asks HEAD to be pulled' ' rm -fr downstream.git &&
Signature · 1 line
An old man doll... just what I always wanted! - Clara
PATCH 3/3 request-pull: document -o/--output
In reply to Bagas SanjayaDocument the option in git-request-pull(1), as well as usage example (along with shell redirection method).
--- Documentation/git-request-pull.txt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
Documentation/git-request-pull.txt +14 -2
@@ -8,7 +8,7 @@ git-request-pull - Generates a summary of pending changes SYNOPSIS -------- [verse] -'git request-pull' [-p] <start> <url> [<end>] +'git request-pull' [-p] [-o | --output <file>] <start> <url> [<end>] DESCRIPTION -----------
@@ -29,6 +29,10 @@ OPTIONS -p:: Include patch text in the output. +-o <file>:: +--output <file>:: + Write the request to the specified file. + <start>:: Commit to start at. This names a commit that is already in the upstream history.
@@ -64,6 +68,15 @@ which will produce a request to the upstream, summarizing the changes between the `v1.0` release and your `master`, to pull it from your public repository. +To generate the request to a file for later editing, you can either +use shell redirection: + + git request-pull v1.0 https://git.ko.xz/project master > request + +or with `-o` option: + + git request-pull -o request v1.0 https://git.ko.xz/project master + If you pushed your change to a branch whose name is different from the one you have locally, e.g.
@@ -73,7 +86,6 @@ then you can ask that to be pulled with git request-pull v1.0 https://git.ko.xz/project master:for-linus - GIT --- Part of the linkgit:git[1] suite
Signature · 1 line
An old man doll... just what I always wanted! - Clara