From 41732e41130c2aee1f15ef83412ce2b0bb338bd0 Mon Sep 17 00:00:00 2001 From: vanpipy Date: Wed, 18 Nov 2020 22:08:39 +0800 Subject: [PATCH 1/3] feat(create-branch): add optional --from to set the start point --- bin/git-create-branch | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/bin/git-create-branch b/bin/git-create-branch index c0d1dd4..6e27c0c 100755 --- a/bin/git-create-branch +++ b/bin/git-create-branch @@ -20,6 +20,12 @@ do REMOTE=origin fi ;; + --from) + if [[ -n $2 ]]; then + START_POINT=$2 + shift + fi + ;; *) BRANCH=$1 esac @@ -44,9 +50,15 @@ then rm -f "$stderr" if [ $REMOTE_EXIT -eq 0 ] then - git push $REMOTE HEAD:refs/heads/$BRANCH - git fetch $REMOTE - git checkout --track -b $BRANCH $REMOTE/$BRANCH + if [[ -n $START_POINT ]]; then + git fetch $REMOTE + git checkout --track -b $BRANCH $START_POINT + git push $REMOTE HEAD:refs/heads/$BRANCH + else + git push $REMOTE HEAD:refs/heads/$BRANCH + git fetch $REMOTE + git checkout --track -b $BRANCH $REMOTE/$BRANCH + fi exit $? else echo @@ -56,4 +68,9 @@ then fi fi -git checkout -b $BRANCH +if [[ -n $START_POINT ]] +then + git checkout -b $BRANCH $START_POINT +else + git checkout -b $BRANCH +fi From d3772eb469e665d376d2c7b67ff42c36fa2b3b0a Mon Sep 17 00:00:00 2001 From: vanpipy Date: Wed, 18 Nov 2020 22:50:13 +0800 Subject: [PATCH 2/3] feat(feature): checkout from start point if exists --- bin/git-feature | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/bin/git-feature b/bin/git-feature index 8712008..3a5e0ce 100755 --- a/bin/git-feature +++ b/bin/git-feature @@ -32,6 +32,10 @@ do --squash ) merge_mode="--squash" ;; + --from ) + start_point=$2 + shift + ;; * ) argv+=($1) ;; @@ -55,10 +59,24 @@ else else branch="$branch_prefix"/"${argv[0]}" fi - if [[ -n $remote ]] + + if [[ -n $remote ]] && [[ -z $start_point ]] then git create-branch -r $remote $branch - else + fi + + if [[ -z $remote ]] && [[ -z $start_point ]] + then git create-branch $branch fi + + if [[ -n $remote ]] && [[ -n $start_point ]] + then + git create-branch -r $remote --from $start_point $branch + fi + + if [[ -z $remote ]] && [[ -n $start_point ]] + then + git create-branch --from $start_point $branch + fi fi From b2b5c97105aa891ee36db742584b0e88017160ff Mon Sep 17 00:00:00 2001 From: vanpipy Date: Thu, 19 Nov 2020 12:10:10 +0800 Subject: [PATCH 3/3] doc: add the usage of the parameter `--from` for create-branch and feature --- man/git-create-branch.1 | 8 +++++++- man/git-create-branch.html | 10 +++++++--- man/git-create-branch.md | 4 ++++ man/git-feature.1 | 8 +++++++- man/git-feature.html | 12 ++++++++---- man/git-feature.md | 4 ++++ 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/man/git-create-branch.1 b/man/git-create-branch.1 index 2dd8c5b..4e1e242 100644 --- a/man/git-create-branch.1 +++ b/man/git-create-branch.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "GIT\-CREATE\-BRANCH" "1" "June 2019" "" "Git Extras" +.TH "GIT\-CREATE\-BRANCH" "1" "November 2020" "" "Git Extras" . .SH "NAME" \fBgit\-create\-branch\fR \- Create branches @@ -19,6 +19,12 @@ Creates local branch named and optionally sets up a remote tracking Setup a remote tracking branch using \fBremote_name\fR\. If \fBremote_name\fR is not supplied, use \fBorigin\fR by default\. . .P +<\-\-from [start_point]> +. +.P +Setup a start point when the branch created\. If \fB\-\-from\fR is not supplied, use the current branch by default\. +. +.P . .P diff --git a/man/git-create-branch.html b/man/git-create-branch.html index e0a054f..88a3333 100644 --- a/man/git-create-branch.html +++ b/man/git-create-branch.html @@ -90,6 +90,10 @@

Setup a remote tracking branch using remote_name. If remote_name is not supplied, use origin by default.

+

<--from [start_point]>

+ +

Setup a start point when the branch created. If --from is not supplied, use the current branch by default.

+

<branchname>

The name of the branch to create.

@@ -141,8 +145,8 @@ $ git create-branch -r upstream integration

AUTHOR

-

Written by Jonhnny Weslley <jw@jonhnnyweslley.net> -Modified by Mark Pitman <mark.pitman@gmail.com>, Brian Murrell <btmurrell@gmail.com>.

+

Written by Jonhnny Weslley <jw@jonhnnyweslley.net> +Modified by Mark Pitman <mark.pitman@gmail.com>, Brian Murrell <btmurrell@gmail.com>.

REPORTING BUGS

@@ -155,7 +159,7 @@ Modified by Mark Pitman < +. +.P +Setup a start point when the branch created\. If \fB\-\-from\fR is not supplied, use the current branch by default\. +. +.P . .P diff --git a/man/git-feature.html b/man/git-feature.html index b480aa6..36f4052 100644 --- a/man/git-feature.html +++ b/man/git-feature.html @@ -93,6 +93,10 @@

Setup a remote tracking branch using remote_name. If remote_name is not supplied, use origin by default.

+

<--from [start_point]>

+ +

Setup a start point when the branch created. If --from is not supplied, use the current branch by default.

+

<finish>

Merge and delete the feature branch.

@@ -136,9 +140,9 @@ $ git features finish dependencies

AUTHOR

-

Written by Jesús Espino <jespinog@gmail.com>
-Modified by Mark Pitman <mark.pitman@gmail.com>
-Modified by Carlos Prado <carlos.prado@cpradog.com>

+

Written by Jesús Espino <jespinog@gmail.com>
+Modified by Mark Pitman <mark.pitman@gmail.com>
+Modified by Carlos Prado <carlos.prado@cpradog.com>

REPORTING BUGS

@@ -151,7 +155,7 @@ Modified by Carlos Prado <