git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joshua Watt <jpewhacker@gmail.com>
To: git@vger.kernel.org
Cc: Joshua Watt <JPEWhacker@gmail.com>
Subject: [PATCH] subtree: Teach push the --force option
Date: Wed, 30 Jan 2019 12:50:47 -0600	[thread overview]
Message-ID: <20190130185047.15401-1-JPEWhacker@gmail.com> (raw)

Force pushing to subtree remotes can occasionally be a useful workflow,
particularly when the remote uses a workflow like GitHub pull requests.

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
---
 contrib/subtree/git-subtree.sh  | 14 +++++++++++++-
 contrib/subtree/git-subtree.txt |  9 +++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 147201dc6c..39792198b4 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -29,6 +29,8 @@ onto=         try connecting new tree to an existing one
 rejoin        merge the new branch back into HEAD
  options for 'add', 'merge', and 'pull'
 squash        merge subtree changes as a single commit
+ options for 'push'
+f,force       force push
 "
 eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
 
@@ -48,6 +50,7 @@ annotate=
 squash=
 message=
 prefix=
+force=
 
 debug () {
 	if test -n "$debug"
@@ -137,6 +140,9 @@ do
 	--no-squash)
 		squash=
 		;;
+	-f)
+		force=1
+		;;
 	--)
 		break
 		;;
@@ -892,7 +898,13 @@ cmd_push () {
 		refspec=$2
 		echo "git push using: " "$repository" "$refspec"
 		localrev=$(git subtree split --prefix="$prefix") || die
-		git push "$repository" "$localrev":"refs/heads/$refspec"
+		if test -n "$force"
+		then
+			fopt="--force"
+		else
+			fopt=""
+		fi
+		git push $fopt "$repository" "$localrev":"refs/heads/$refspec"
 	else
 		die "'$dir' must already exist. Try 'git subtree add'."
 	fi
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 352deda69d..e956e6ab7d 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -175,6 +175,15 @@ remain intact and can be later split and send upstream to the
 subproject.
 
 
+OPTIONS FOR push
+----------------
+-f::
+--force::
+	This option is only valid for the push command
++
+Force push to the remote branch, just like gitlink:git-push[1]
+
+
 OPTIONS FOR split
 -----------------
 --annotate=<annotation>::
-- 
2.20.1


                 reply	other threads:[~2019-01-30 18:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190130185047.15401-1-JPEWhacker@gmail.com \
    --to=jpewhacker@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).