diff options
author | Michael Allen <michael@michaelallen.io> | 2015-02-17 17:09:45 +0000 |
---|---|---|
committer | Michael Allen <michael@michaelallen.io> | 2015-02-17 17:09:45 +0000 |
commit | f05711dbcf196f98f0e08d783f760d47d98b93a6 (patch) | |
tree | 9906f0cf7d540d35fc1d46fd5d3396d3d50c8207 | |
parent | 19d104ac60b19c1a11a72f4ebbb63e933552fcf0 (diff) | |
download | git-sonar-f05711dbcf196f98f0e08d783f760d47d98b93a6.tar.gz git-sonar-f05711dbcf196f98f0e08d783f760d47d98b93a6.zip |
untracked files reporting
-rwxr-xr-x | git-base.sh | 12 | ||||
-rwxr-xr-x | test-files.sh | 33 | ||||
-rwxr-xr-x | test.sh | 1 |
3 files changed, 46 insertions, 0 deletions
diff --git a/git-base.sh b/git-base.sh index d2262d4..d9dc10a 100755 --- a/git-base.sh +++ b/git-base.sh @@ -176,3 +176,15 @@ remote_ahead_of_master() { echo "0" fi } + +porcelain_status() { + echo "$(git status --porcelain 2>/dev/null)" +} + +untracked_files() { + if is_repo; then + git_status="$(porcelain_status)" + untracked="$(echo "$git_status" | grep -p "?? " | wc -l | grep -oEi '[0-9][0-9]*')" + echo "$untracked" + fi +} diff --git a/test-files.sh b/test-files.sh new file mode 100755 index 0000000..ee583cc --- /dev/null +++ b/test-files.sh @@ -0,0 +1,33 @@ +scriptDir="$(cd "$(dirname "$0")"; pwd)" + +source "$scriptDir/git-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_untracked_files() { + cd_to_tmp + git init --quiet + + assertEquals "0" "$(untracked_files)" + + touch foo + assertEquals "1" "$(untracked_files)" + + git add . + assertEquals "0" "$(untracked_files)" + + rm_tmp +} + +. ./shunit/shunit2 @@ -3,3 +3,4 @@ ./test-directories.sh ./test-commits.sh ./test-branches.sh +./test-files.sh |