Skip to content

Commit 1545b2c

Browse files
committed
Check both stashed and unstashed changes before making auto-stash
We need to perform automatic stash if either unstashed or stashed or both changes are available.
1 parent f3d3248 commit 1545b2c

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

libexec/plugins/pipe

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22
# The plugin which allows running a given functions through different types
33
# (aka pre- and post-conditions).
44

5+
has-changes() {
6+
# Check if a current index (HEAD) has staged or non-staged changes
7+
if git diff-index --quiet HEAD && git diff-index --cached --quiet HEAD; then
8+
return 1
9+
fi
10+
return 0
11+
}
12+
513
stash-pipe() {
614
# Makes automatic stash and unstash if possible
715
# usage: stash-pipe <command> [args]...
816

917
git update-index -q --really-refresh
10-
if ! git diff-index --quiet HEAD --; then
18+
if has-changes; then
1119
local message="Elegant Git auto-stash: "
1220
message+="WIP in '$(git rev-parse --abbrev-ref HEAD)' branch "
1321
message+="on $(date "+%Y-%m-%dT%H:%M:%S")"

0 commit comments

Comments
 (0)