git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] request-pull: write to file option
@ 2021-10-03 12:29 Bagas Sanjaya
  2021-10-03 12:29 ` [PATCH 1/3] request-pull: introduce display_message() function Bagas Sanjaya
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Bagas Sanjaya @ 2021-10-03 12:29 UTC (permalink / raw)
  To: git; +Cc: Ryan Anderson, Bagas Sanjaya

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
-- 
An old man doll... just what I always wanted! - Clara


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] request-pull: introduce display_message() function
  2021-10-03 12:29 [PATCH 0/3] request-pull: write to file option Bagas Sanjaya
@ 2021-10-03 12:29 ` Bagas Sanjaya
  2021-10-03 12:29 ` [PATCH 2/3] request-pull: add -o/--output option Bagas Sanjaya
  2021-10-03 12:29 ` [PATCH 3/3] request-pull: document -o/--output Bagas Sanjaya
  2 siblings, 0 replies; 4+ messages in thread
From: Bagas Sanjaya @ 2021-10-03 12:29 UTC (permalink / raw)
  To: git; +Cc: Ryan Anderson, Bagas Sanjaya

Move displaying PR message logic into display_message. While at it, use
local variable $format and $dashline to shorten argument typing to git
show.

Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
---
 git-request-pull.sh | 57 ++++++++++++++++++++++++++++-----------------
 1 file changed, 35 insertions(+), 22 deletions(-)

diff --git a/git-request-pull.sh b/git-request-pull.sh
index 2d0e44656c..88a7a9cf0d 100755
--- a/git-request-pull.sh
+++ b/git-request-pull.sh
@@ -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
-- 
An old man doll... just what I always wanted! - Clara


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] request-pull: add -o/--output option
  2021-10-03 12:29 [PATCH 0/3] request-pull: write to file option Bagas Sanjaya
  2021-10-03 12:29 ` [PATCH 1/3] request-pull: introduce display_message() function Bagas Sanjaya
@ 2021-10-03 12:29 ` Bagas Sanjaya
  2021-10-03 12:29 ` [PATCH 3/3] request-pull: document -o/--output Bagas Sanjaya
  2 siblings, 0 replies; 4+ messages in thread
From: Bagas Sanjaya @ 2021-10-03 12:29 UTC (permalink / raw)
  To: git; +Cc: Ryan Anderson, Bagas Sanjaya

Add -o option (and long dash counterpart --option), which allow users to
write pull request message to the specified file.

Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
---
 git-request-pull.sh     | 28 +++++++++++++++++++++++-----
 t/t5150-request-pull.sh | 13 +++++++++++++
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/git-request-pull.sh b/git-request-pull.sh
index 88a7a9cf0d..f4d6f846d0 100755
--- a/git-request-pull.sh
+++ b/git-request-pull.sh
@@ -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
diff --git a/t/t5150-request-pull.sh b/t/t5150-request-pull.sh
index cb67bac1c4..b87e9c9869 100755
--- a/t/t5150-request-pull.sh
+++ b/t/t5150-request-pull.sh
@@ -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 &&
-- 
An old man doll... just what I always wanted! - Clara


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] request-pull: document -o/--output
  2021-10-03 12:29 [PATCH 0/3] request-pull: write to file option Bagas Sanjaya
  2021-10-03 12:29 ` [PATCH 1/3] request-pull: introduce display_message() function Bagas Sanjaya
  2021-10-03 12:29 ` [PATCH 2/3] request-pull: add -o/--output option Bagas Sanjaya
@ 2021-10-03 12:29 ` Bagas Sanjaya
  2 siblings, 0 replies; 4+ messages in thread
From: Bagas Sanjaya @ 2021-10-03 12:29 UTC (permalink / raw)
  To: git; +Cc: Ryan Anderson, Bagas Sanjaya

Document the option in git-request-pull(1), as well as usage example
(along with shell redirection method).

Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
---
 Documentation/git-request-pull.txt | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-request-pull.txt b/Documentation/git-request-pull.txt
index 4d4392d0f8..4bb07d8865 100644
--- a/Documentation/git-request-pull.txt
+++ b/Documentation/git-request-pull.txt
@@ -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
-- 
An old man doll... just what I always wanted! - Clara


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-03 12:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-03 12:29 [PATCH 0/3] request-pull: write to file option Bagas Sanjaya
2021-10-03 12:29 ` [PATCH 1/3] request-pull: introduce display_message() function Bagas Sanjaya
2021-10-03 12:29 ` [PATCH 2/3] request-pull: add -o/--output option Bagas Sanjaya
2021-10-03 12:29 ` [PATCH 3/3] request-pull: document -o/--output Bagas Sanjaya

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).