summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xradar-base.sh12
-rwxr-xr-xtest1
-rwxr-xr-xtest-stash.sh50
3 files changed, 59 insertions, 4 deletions
diff --git a/radar-base.sh b/radar-base.sh
index 1be76e4..ec907b0 100755
--- a/radar-base.sh
+++ b/radar-base.sh
@@ -470,16 +470,20 @@ zsh_color_remote_commits() {
printf %s "$remote"
}
+stashed_status() {
+ printf '%s' "$(git stash list | wc -l 2>/dev/null)"
+}
+
bash_stash_status() {
- local number_stashes="$(git stash list | wc -l)"
+ local number_stashes="$(stashed_status)"
if [ $number_stashes -gt 0 ]; then
- printf " $number_stashes\x01\033[1;33m\x02=\x01\033[0m\x02)"
+ printf " $number_stashes\x01\033[1;33m\x02=\x01\033[0m\x02"
fi
}
zsh_stash_status() {
- local number_stashes="$(git stash list | wc -l)"
+ local number_stashes="$(stashed_status)"
if [ $number_stashes -gt 0 ]; then
- printf %s " $number_stashes%{$fg_bold[yellow]%}=%{$reset_color%})"
+ printf %s " $number_stashes%{$fg_bold[yellow]%}=%{$reset_color%}"
fi
} \ No newline at end of file
diff --git a/test b/test
index a6a8775..d5213be 100755
--- a/test
+++ b/test
@@ -5,3 +5,4 @@
./test-branches.sh
./test-files.sh
./test-status.sh
+./test-stash.sh \ No newline at end of file
diff --git a/test-stash.sh b/test-stash.sh
new file mode 100755
index 0000000..aecd83c
--- /dev/null
+++ b/test-stash.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+scriptDir="$(cd "$(dirname "$0")"; pwd)"
+
+source "$scriptDir/radar-base.sh"
+
+tmpfile=""
+
+cd_to_tmp() {
+ tmpfile="/tmp/git-prompt-tests-$(time_now)$1"
+ mkdir -p "$tmpfile"
+ cd "$tmpfile"
+}
+
+rm_tmp() {
+ cd $scriptDir
+ rm -rf /tmp/git-prompt-tests*
+}
+
+test_unstashed_status() {
+ cd_to_tmp
+ git init --quiet
+
+ assertEquals "0" "$(stashed_status)"
+
+ rm_tmp
+}
+
+test_stashed_status() {
+ cd_to_tmp
+ git init --quiet
+
+ touch foo
+ git add --all
+ git commit -m "Initial commit" >/dev/null
+ echo "test">foo
+ git stash > /dev/null
+ assertEquals "1" "$(stashed_status)"
+
+ echo "test2">foo
+ git stash > /dev/null
+ assertEquals "2" "$(stashed_status)"
+
+ git stash drop > /dev/null
+ assertEquals "1" "$(stashed_status)"
+
+
+ rm_tmp
+}
+
+. ./shunit/shunit2