Skip to content

Commit

Permalink
setup-development-environment.bash: Only stash if needed, should fix
Browse files Browse the repository at this point in the history
…#111

Signed-off-by: 林博仁(Buo-Ren Lin) <[email protected]>
  • Loading branch information
brlin-tw committed May 8, 2018
1 parent b9228b6 commit ad4bd92
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions setup-development-environment.bash
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,21 @@ init(){
&& printf "done\n"

printf "Activate Git smudge filter...\n"
git stash save &>/dev/null || true
# git - How do I programmatically determine if there are uncommitted changes? - Stack Overflow
# https://stackoverflow.com/questions/3878624/how-do-i-programmatically-determine-if-there-are-uncommitted-changes
# DOC: git-diff-index(1) manpage: OPTIONS: --quiet, --exit-code
local stash_is_needed=false
if ! git diff-index --quiet HEAD --; then
stash_is_needed=true
fi
if test "${stash_is_needed}" = 'true'; then
git stash save &>/dev/null
fi
rm .git/index
git checkout HEAD -- "$(git rev-parse --show-toplevel)" >/dev/null
git stash pop &>/dev/null || true
if test "${stash_is_needed}" = 'true'; then
git stash pop &>/dev/null
fi; unset stash_is_needed
printf "done.\n"

exit 0
Expand Down

0 comments on commit ad4bd92

Please sign in to comment.