git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/4] contrib/subtree: Teach push to use --force option

From
Paul Campbell <pcampbell@kemitix.net>
Date
Mar 13, 2013, 22:32 UTC
Message-ID
<1363213963-4065-3-git-send-email-pcampbell@kemitix.net>
In-Reply-To
<1363213963-4065-1-git-send-email-pcampbell@kemitix.net>
From: James Roper <jroper@vz.net>
Allow the --force option to be passed to the child push command.
Signed-off-by: Paul Campbell <pcampbell@kemitix.net>
---
 contrib/subtree/git-subtree.sh  | 9 ++++++++-
 contrib/subtree/git-subtree.txt | 5 +++++
 2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index c68cc6f..2d9b071 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -26,6 +26,8 @@ b,branch=     create a new branch from the split subtree
 ignore-joins  ignore prior --rejoin commits
 onto=         try connecting new tree to an existing one
 rejoin        merge the new branch back into HEAD
+ options for 'push'
+f,force       use force push
  options for 'add', 'merge', 'pull' and 'push'
 squash        merge subtree changes as a single commit
 "
@@ -84,6 +86,7 @@ while [ $# -gt 0 ]; do
 		-b) branch="$1"; shift ;;
 		-P) prefix="$1"; shift ;;
 		-m) message="$1"; shift ;;
+		-f|--force) force=1 ;;
 		--no-prefix) prefix= ;;
 		--onto) onto="$1"; shift ;;
 		--no-onto) onto= ;;
@@ -712,12 +715,16 @@ cmd_push()
 	    die "You must provide <repository> <refspec>"
 	fi
 	if [ -e "$dir" ]; then
+	    push_opts=
+	    if [ "$force" == "1" ]; then
+		push_opts="$push_opts --force"
+	    fi
 	    repository=$1
 	    refspec=$2
 	    echo "git push using: " $repository $refspec
 	    rev=$(git subtree split --prefix=$prefix)
 	    if [ -n "$rev" ]; then
-		git push $repository $rev:refs/heads/$refspec
+		git push $push_opts $repository $rev:refs/heads/$refspec
 	    else
 		die "Couldn't push, 'git subtree split' failed."
 	    fi
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 7ba853e..97dd3c9 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -255,6 +255,11 @@ OPTIONS FOR split
 	'--rejoin' when you split, because you don't want the
 	subproject's history to be part of your project anyway.
 
+OPTIONS FOR push
+----------------
+-f::
+--force::
+    Uses 'git push --force'.
 
 EXAMPLE 1. Add command
 ----------------------
-- 
1.8.2
Previous: Paul CampbellNext: Paul Campbell
Message 3 of 10 in “contrib/subtree: general updates”
  1. 0/4 contrib/subtree: general updatesPaul Campbell, Mar 13, 2013
  2. 1/4 contrib/subtree: Teach push to abort if split failsPaul Campbell, Mar 13, 2013
  3. 2/4 contrib/subtree: Teach push to use --force optionPaul Campbell, Mar 13, 2013
  4. 3/4 contrib/subtree: Fix typo (s/incldued/included/)Paul Campbell, Mar 13, 2013
  5. 4/4 contrib/subtree: Replace invisible carriage return with a visible \rPaul Campbell, Mar 13, 2013
  6. Paul CampbellMar 13, 2013
  7. contrib/subtree: Replace invisible carriage return with a visible \rPaul Campbell, Mar 13, 2013
  8. Miles BaderMar 14, 2013
  9. Junio C HamanoMar 14, 2013
  10. Paul CampbellMar 24, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.