Skip to content

Commit 818996a

Browse files
authored
feat: add branch command for creating branches without a prefix (#62)
* feat: added support to create branches without a prefix * fix: added completion to branch command, updated readme and improved check for valid branch * docs: added branch section to readme
1 parent 7e4d746 commit 818996a

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ fundle plugin joseluisq/gitnow
6464
| [assume](#assume) | | Ignores changes in certain files temporarily. |
6565
| [logs](#logs) | Alt + L | Shows logs in a fancy way. |
6666
| __Gitflow__ | | |
67+
| [branch](#branch) (1) | | Creates a new branch from current branch. |
6768
| [feature](#feature) (1) | Alt + F | Creates a new _feature_ ([Gitflow](https://github.com/nvie/gitflow)) branch from current branch. |
6869
| [hotfix](#hotfix) (1) | Alt + H | Creates a new _hotfix_ ([Gitflow](https://github.com/nvie/gitflow)) branch from current branch. |
6970
| [bugfix](#bugfix) (1) | | Creates a new _bugfix_ ([Gitflow](https://github.com/nvie/gitflow)) branch from current branch. |
@@ -390,6 +391,19 @@ assume Cargo.toml README.md
390391
assume -n Cargo.toml README.md
391392
```
392393

394+
### branch
395+
396+
Creates a new branch ([Gitflow](https://github.com/nvie/gitflow)) from current branch.
397+
398+
__Note:__ Your new branch will always be lowercase without special characters or whitespaces (underscores instead).
399+
400+
```sh
401+
branch CODE-1234
402+
# > code-1234
403+
branch "This is my New Branch"
404+
# > this_is_my_new_branch
405+
```
406+
393407
### feature
394408

395409
Creates a new feature ([Gitflow](https://github.com/nvie/gitflow)) branch from current branch.

completions/branch.fish

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# GitNow — Speed up your Git workflow. 🐠
2+
# https://github.com/joseluisq/gitnow
3+
4+
# Branch command
5+
6+
__gitnow_load_git_functions
7+
8+
complete -f -k -x -c branch -a '(__fish_git_branches)'

conf.d/gitnow.fish

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -g gitnow_version 2.13.0
55

66
# Default global variables
77
set -q GITNOW_CONFIG_FILE; or set -g GITNOW_CONFIG_FILE ~/.gitnow
8-
set -g gitnow_commands 'all' 'assume' 'bitbucket' 'bugfix' 'commit' 'commit-all' 'feature' 'github' 'gitnow' 'hotfix' 'logs' 'merge' 'move' 'pull' 'push' 'release' 'show' 'stage' 'state' 'tag' 'unstage' 'untracked' 'upstream'
8+
set -g gitnow_commands 'all' 'assume' 'bitbucket' 'bugfix' 'commit' 'commit-all' 'branch' 'feature' 'github' 'gitnow' 'hotfix' 'logs' 'merge' 'move' 'pull' 'push' 'release' 'show' 'stage' 'state' 'tag' 'unstage' 'untracked' 'upstream'
99

1010
if set -q __fish_config_dir
1111
set -g fish_config "$__fish_config_dir"
@@ -239,6 +239,15 @@ function upstream -d "Gitnow: Commit all changes and push them to remote server"
239239
push
240240
end
241241

242+
function branch -d "GitNow: Creates a new Gitflow branch from current branch" -a xbranch
243+
if not __gitnow_is_git_repository
244+
__gitnow_msg_not_valid_repository "branch"
245+
return
246+
end
247+
248+
__gitnow_check_create_branch "$xbranch"
249+
end
250+
242251
function feature -d "GitNow: Creates a new Gitflow feature branch from current branch" -a xbranch
243252
if not __gitnow_is_git_repository
244253
__gitnow_msg_not_valid_repository "feature"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# GitNow — Speed up your Git workflow. 🐠
2+
# https://github.com/joseluisq/gitnow
3+
4+
function __gitnow_check_create_branch -a xbranch
5+
set -l xfound (__gitnow_check_if_branch_exist $xbranch)
6+
7+
if test -n "$xbranch"
8+
if test $xfound -eq 1
9+
echo "Branch `$xbranch` already exists. Nothing to do."
10+
else
11+
command git stash
12+
__gitnow_new_branch_switch "$xbranch"
13+
command git stash pop
14+
end
15+
else
16+
echo "Branch name is required."
17+
end
18+
end

functions/__gitnow_manual.fish

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ function __gitnow_manual -d "Gitnow: Manual page like"
5959
echo " "(set_color --bold)"assume"(set_color normal)
6060
echo " Ignore changes in certain files temporarily."
6161
echo
62+
echo " "(set_color --bold)"branch"(set_color normal)
63+
echo " Create a new branch from the current branch."
64+
echo
6265
echo " "(set_color --bold)"feature"(set_color normal)
6366
echo " Create a new Gitflow feature branch from the current branch."
6467
echo

0 commit comments

Comments
 (0)