{"thread":{"id":"50365","subject":"[PATCH] subtree: Teach push the --force option","startedAt":"2019-01-30T18:50:54Z","lastAt":"2019-01-30T18:50:54Z","messageCount":1,"participants":["Joshua Watt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"368151","messageId":"20190130185047.15401-1-JPEWhacker@gmail.com","threadId":"50365","inReplyTo":null,"subject":"[PATCH] subtree: Teach push the --force option","fromName":"Joshua Watt","fromEmail":"jpewhacker@gmail.com","sentAt":"2019-01-30T18:50:47Z","receivedAt":"2019-01-30T18:50:54Z","isPatch":true,"sender":{"key":"jpewhacker@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6453652?v=4"},"body":"Force pushing to subtree remotes can occasionally be a useful workflow,\nparticularly when the remote uses a workflow like GitHub pull requests.\n\nSigned-off-by: Joshua Watt <JPEWhacker@gmail.com>\n---\n contrib/subtree/git-subtree.sh  | 14 +++++++++++++-\n contrib/subtree/git-subtree.txt |  9 +++++++++\n 2 files changed, 22 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh\nindex 147201dc6c..39792198b4 100755\n--- a/contrib/subtree/git-subtree.sh\n+++ b/contrib/subtree/git-subtree.sh\n@@ -29,6 +29,8 @@ onto=         try connecting new tree to an existing one\n rejoin        merge the new branch back into HEAD\n  options for 'add', 'merge', and 'pull'\n squash        merge subtree changes as a single commit\n+ options for 'push'\n+f,force       force push\n \"\n eval \"$(echo \"$OPTS_SPEC\" | git rev-parse --parseopt -- \"$@\" || echo exit $?)\"\n \n@@ -48,6 +50,7 @@ annotate=\n squash=\n message=\n prefix=\n+force=\n \n debug () {\n \tif test -n \"$debug\"\n@@ -137,6 +140,9 @@ do\n \t--no-squash)\n \t\tsquash=\n \t\t;;\n+\t-f)\n+\t\tforce=1\n+\t\t;;\n \t--)\n \t\tbreak\n \t\t;;\n@@ -892,7 +898,13 @@ cmd_push () {\n \t\trefspec=$2\n \t\techo \"git push using: \" \"$repository\" \"$refspec\"\n \t\tlocalrev=$(git subtree split --prefix=\"$prefix\") || die\n-\t\tgit push \"$repository\" \"$localrev\":\"refs/heads/$refspec\"\n+\t\tif test -n \"$force\"\n+\t\tthen\n+\t\t\tfopt=\"--force\"\n+\t\telse\n+\t\t\tfopt=\"\"\n+\t\tfi\n+\t\tgit push $fopt \"$repository\" \"$localrev\":\"refs/heads/$refspec\"\n \telse\n \t\tdie \"'$dir' must already exist. Try 'git subtree add'.\"\n \tfi\ndiff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt\nindex 352deda69d..e956e6ab7d 100644\n--- a/contrib/subtree/git-subtree.txt\n+++ b/contrib/subtree/git-subtree.txt\n@@ -175,6 +175,15 @@ remain intact and can be later split and send upstream to the\n subproject.\n \n \n+OPTIONS FOR push\n+----------------\n+-f::\n+--force::\n+\tThis option is only valid for the push command\n++\n+Force push to the remote branch, just like gitlink:git-push[1]\n+\n+\n OPTIONS FOR split\n -----------------\n --annotate=<annotation>::\n-- \n2.20.1\n\n"}]}