Skip to content

Commit

Permalink
feat: stash changes only if there are uncommited changes
Browse files Browse the repository at this point in the history
  • Loading branch information
joseluisq committed Jul 21, 2020
1 parent 665be6b commit 6acf46f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions conf.d/gitnow.fish
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,21 @@ function move -d "GitNow: Switch from current branch to another but stashing unc
return
end

command git stash
set -l v_stashed (__gitnow_has_uncommited_changes)

# Stash changes before checkout for uncommited changes only
if test $v_stashed
command git stash
end

command git checkout $v_branch

# --no-apply-stash
if test -n "$v_no_apply_stash"
echo "Stashed changes were not applied. Use `git stash pop` to apply them."
else
end

if begin test $v_stashed; and not test -n "$v_no_apply_stash"; end
command git stash pop
echo "Stashed changes applied."
end
Expand Down
4 changes: 4 additions & 0 deletions functions/__gitnow_functions.fish
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,7 @@ end
function __gitnow_is_git_repository
command git rev-parse --git-dir >/dev/null 2>&1
end

function __gitnow_has_uncommited_changes
command git diff-index --quiet HEAD -- || echo "1" 2>&1
end

0 comments on commit 6acf46f

Please sign in to comment.