Permalink
Browse files

no_changes sometimes lies to us, so don't try to apply a stash if we …

…didn't save a stash.
  • Loading branch information...
1 parent 1b137bb commit 6955c7d8c0a724bad39de968be68c329527b47d4 @eventualbuddha eventualbuddha committed Nov 15, 2011
Showing with 13 additions and 4 deletions.
  1. +13 −4 bin/hack
View
@@ -5,6 +5,8 @@ CURRENT=${CURRENT#refs/heads/}
gitdir=$(git rev-parse --git-dir)
rootdir=$(dirname "$gitdir")
+logfile=/tmp/hack-$$.log
+
if [ "$rootdir" = "." ]; then
rootdir=$PWD
fi
@@ -77,9 +79,11 @@ git() {
echo -e "+ ${GREEN}git $@${NO_COLOR}"
fi
- eval "$GIT $@"
+ eval "$GIT $@ | tee $logfile"
}
+trap 'cleanup' EXIT
+
no_changes () {
$GIT diff-index --quiet --cached HEAD -- &&
$GIT diff-files --quiet
@@ -91,9 +95,13 @@ stash_changes_if_needed() {
else
git stash ||
die "Could not stash your local changes. Something must be really wrong."
- stashed=true
- trap 'check_stash' EXIT
+ if cat $logfile | grep "No local changes to save" >/dev/null; then
+ # nothing to stash, no_changes lied to us
+ stashed=false
+ else
+ stashed=true
+ fi
fi
}
@@ -105,10 +113,11 @@ pop_stash_if_needed() {
fi
}
-check_stash() {
+cleanup() {
if [ "$stashed" = true ]; then
warn "Your stashed changes were not applied because an error occurred. Don't panic. They are not lost. Look for them in \"git stash list\"."
fi
+ rm -f $logfile
}
switch_to_tracking() {

0 comments on commit 6955c7d

Please sign in to comment.