Skip to content

Commit

Permalink
Merge pull request #895 from vanpipy/feature/optional-start-point-whe…
Browse files Browse the repository at this point in the history
…n-creeate-branch

feat(#861): add optional parameter --from to set the start point
  • Loading branch information
spacewander authored Nov 21, 2020
2 parents 18bcfcd + b2b5c97 commit 444722c
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 15 deletions.
25 changes: 21 additions & 4 deletions bin/git-create-branch
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ do
REMOTE=origin
fi
;;
--from)
if [[ -n $2 ]]; then
START_POINT=$2
shift
fi
;;
*)
BRANCH=$1
esac
Expand All @@ -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
Expand All @@ -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
22 changes: 20 additions & 2 deletions bin/git-feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ do
--squash )
merge_mode="--squash"
;;
--from )
start_point=$2
shift
;;
* )
argv+=($1)
;;
Expand All @@ -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
8 changes: 7 additions & 1 deletion man/git-create-branch.1
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,6 +19,12 @@ Creates local branch named <branchname> 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
<branchname>
.
.P
Expand Down
10 changes: 7 additions & 3 deletions man/git-create-branch.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/git-create-branch.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Creates local branch named &lt;branchname&gt; and optionally sets up a remote tr

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

&lt;--from [start_point]&gt;

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

&lt;branchname&gt;

The name of the branch to create.
Expand Down
8 changes: 7 additions & 1 deletion man/git-feature.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-FEATURE" "1" "April 2020" "" "Git Extras"
.TH "GIT\-FEATURE" "1" "November 2020" "" "Git Extras"
.
.SH "NAME"
\fBgit\-feature\fR \- Create/Merge feature branch
Expand All @@ -28,6 +28,12 @@ use \fBbranch_prefix\fR instead of \fBfeature\fR
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
<finish>
.
.P
Expand Down
12 changes: 8 additions & 4 deletions man/git-feature.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/git-feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ git-feature(1) -- Create/Merge feature branch

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

&lt;--from [start_point]&gt;

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

&lt;finish&gt;

Merge and delete the feature branch.
Expand Down

0 comments on commit 444722c

Please sign in to comment.