diff options
author | Michael Allen <michael@michaelallen.io> | 2015-07-23 19:17:42 +0100 |
---|---|---|
committer | Michael Allen <michael@michaelallen.io> | 2015-07-23 19:17:42 +0100 |
commit | 292a040b4abbbf085b97f7b285e67c97960dc510 (patch) | |
tree | ab4e6510785ef1a2ec75daf971a9cacf98317f5f | |
parent | 815fce9dc7668a7f1ea59cd557f718a1a1e12101 (diff) | |
download | git-sonar-292a040b4abbbf085b97f7b285e67c97960dc510.tar.gz git-sonar-292a040b4abbbf085b97f7b285e67c97960dc510.zip |
remove unnecessary added/modified/etc
Diffstat (limited to '')
-rwxr-xr-x | git-base.sh | 40 | ||||
-rwxr-xr-x | test-files.sh | 30 | ||||
-rwxr-xr-x | test-status.sh | 42 |
3 files changed, 45 insertions, 67 deletions
diff --git a/git-base.sh b/git-base.sh index b45e42d..2385592 100755 --- a/git-base.sh +++ b/git-base.sh @@ -172,15 +172,6 @@ remote_ahead_of_master() { fi } -added="A%{$reset_color%}" -modified="M%{$reset_color%}" -deleted="D%{$reset_color%}" -renamed="R%{$reset_color%}" -copied="C%{$reset_color%}" -us="U%{$reset_color%}" -them="T%{$reset_color%}" -both="B%{$reset_color%}" - # Diacritic marks for overlaying an arrow over A D C etc #us="\xE2\x83\x97{$reset_color%}" #them="\xE2\x83\x96%{$reset_color%}" @@ -230,6 +221,9 @@ porcelain_status() { staged_status() { local gitStatus=${1:-"$(porcelain_status)"} + local prefix=${2:-""} + local suffix=${3:-""} + local staged_string="" local filesModified="$(echo "$gitStatus" | grep -p "M[ACDR ] " | wc -l | grep -oEi '[1-9][0-9]*')" local filesAdded="$(echo "$gitStatus" | grep -p "A[MCDR ] " | wc -l | grep -oEi '[1-9][0-9]*')" @@ -238,25 +232,27 @@ staged_status() { local filesCopied="$(echo "$gitStatus" | grep -p "C[AMDR ] " | wc -l | grep -oEi '[1-9][0-9]*')" if [ -n "$filesAdded" ]; then - staged_string="$staged_string$filesAdded$staged$added" + staged_string="$staged_string$filesAdded${prefix}A${suffix}" fi if [ -n "$filesDeleted" ]; then - staged_string="$staged_string$filesDeleted$staged$deleted" + staged_string="$staged_string$filesDeleted${prefix}D${suffix}" fi if [ -n "$filesModified" ]; then - staged_string="$staged_string$filesModified$staged$modified" + staged_string="$staged_string$filesModified${prefix}M${suffix}" fi if [ -n "$filesRenamed" ]; then - staged_string="$staged_string$filesRenamed$staged$renamed" + staged_string="$staged_string$filesRenamed${prefix}R${suffix}" fi if [ -n "$filesCopied" ]; then - staged_string="$staged_string$filesCopied$staged$copied" + staged_string="$staged_string$filesCopied${prefix}C${suffix}" fi echo "$staged_string" } conflicted_status() { local gitStatus=${1:-"$(porcelain_status)"} + local prefix=${2:-""} + local suffix=${3:-""} local conflicted_string="" local filesUs="$(echo "$gitStatus" | grep -p "[AD]U " | wc -l | grep -oEi '[1-9][0-9]*')" @@ -264,35 +260,41 @@ conflicted_status() { local filesBoth="$(echo "$gitStatus" | grep -E "(UU|AA|DD) " | wc -l | grep -oEi '[1-9][0-9]*')" if [ -n "$filesUs" ]; then - conflicted_string="$conflicted_string$filesUs$conflicted$us" + conflicted_string="$conflicted_string$filesUs${prefix}U${suffix}" fi if [ -n "$filesThem" ]; then - conflicted_string="$conflicted_string$filesThem$conflicted$them" + conflicted_string="$conflicted_string$filesThem${prefix}T${suffix}" fi if [ -n "$filesBoth" ]; then - conflicted_string="$conflicted_string$filesBoth$conflicted$both" + conflicted_string="$conflicted_string$filesBoth${prefix}B${suffix}" fi echo "$conflicted_string" } unstaged_status() { local gitStatus=${1:-"$(porcelain_status)"} + local prefix=${2:-""} + local suffix=${3:-""} local unstaged_string="" + local filesModified="$(echo "$gitStatus" | grep -p "[AMCDR ]M " | wc -l | grep -oEi '[1-9][0-9]*')" local filesDeleted="$(echo "$gitStatus" | grep -p "[AMCR ]D " | wc -l | grep -oEi '[1-9][0-9]*')" if [ -n "$filesDeleted" ]; then - unstaged_string="$unstaged_string$filesDeleted$unstaged$deleted" + unstaged_string="$unstaged_string$filesDeleted${prefix}D${suffix}" fi if [ -n "$filesModified" ]; then - unstaged_string="$unstaged_string$filesModified$unstaged$modified" + unstaged_string="$unstaged_string$filesModified${prefix}M${suffix}" fi echo "$unstaged_string" } untracked_status() { local gitStatus=${1:-"$(porcelain_status)"} + local prefix=${2:-""} + local suffix=${3:-""} local untracked_string="" + local filesUntracked="$(echo "$gitStatus" | grep -p "?? " | wc -l | grep -oEi '[1-9][0-9]*')" if [ -n "$filesUntracked" ]; then diff --git a/test-files.sh b/test-files.sh index 4c5e9c4..2bfa944 100755 --- a/test-files.sh +++ b/test-files.sh @@ -42,10 +42,10 @@ test_unstaged_modified_files() { git commit -m "foo and bar" >/dev/null echo "foo" >> foo - assertEquals "1$unstaged$modified" "$(unstaged_status)" + assertEquals "1M" "$(unstaged_status)" echo "bar" >> bar - assertEquals "2$unstaged$modified" "$(unstaged_status)" + assertEquals "2M" "$(unstaged_status)" rm_tmp } @@ -62,10 +62,10 @@ test_unstaged_deleted_files() { git commit -m "foo and bar" >/dev/null rm foo - assertEquals "1$unstaged$deleted" "$(unstaged_status)" + assertEquals "1D" "$(unstaged_status)" rm bar - assertEquals "2$unstaged$deleted" "$(unstaged_status)" + assertEquals "2D" "$(unstaged_status)" rm_tmp } @@ -78,11 +78,11 @@ test_staged_added_files() { touch foo git add . - assertEquals "1$staged$added" "$(staged_status)" + assertEquals "1A" "$(staged_status)" touch bar git add . - assertEquals "2$staged$added" "$(staged_status)" + assertEquals "2A" "$(staged_status)" rm_tmp } @@ -100,11 +100,11 @@ test_staged_modified_files() { echo "foo" >> foo git add . - assertEquals "1$staged$modified" "$(staged_status)" + assertEquals "1M" "$(staged_status)" echo "bar" >> bar git add . - assertEquals "2$staged$modified" "$(staged_status)" + assertEquals "2M" "$(staged_status)" rm_tmp } @@ -122,11 +122,11 @@ test_staged_deleted_files() { rm foo git add . - assertEquals "1$staged$deleted" "$(staged_status)" + assertEquals "1D" "$(staged_status)" rm bar git add . - assertEquals "2$staged$deleted" "$(staged_status)" + assertEquals "2D" "$(staged_status)" rm_tmp } @@ -144,11 +144,11 @@ test_staged_renamed_files() { mv foo foo2 git add . - assertEquals "1$staged$renamed" "$(staged_status)" + assertEquals "1R" "$(staged_status)" mv bar bar2 git add . - assertEquals "2$staged$renamed" "$(staged_status)" + assertEquals "2R" "$(staged_status)" rm_tmp } @@ -176,7 +176,7 @@ test_conflicted_both_changes() { git merge foo2 >/dev/null - assertEquals "1$conflicted$both" "$(conflicted_status)" + assertEquals "1B" "$(conflicted_status)" rm_tmp } @@ -204,7 +204,7 @@ test_conflicted_them_changes() { git merge foo2 >/dev/null - assertEquals "1$conflicted$them" "$(conflicted_status)" + assertEquals "1T" "$(conflicted_status)" rm_tmp } @@ -232,7 +232,7 @@ test_conflicted_us_changes() { git merge foo2 >/dev/null - assertEquals "1$conflicted$us" "$(conflicted_status)" + assertEquals "1U" "$(conflicted_status)" rm_tmp } diff --git a/test-status.sh b/test-status.sh index 025fc69..8b9cf2f 100755 --- a/test-status.sh +++ b/test-status.sh @@ -2,30 +2,6 @@ scriptDir="$(cd "$(dirname "$0")"; pwd)" source "$scriptDir/git-base.sh" -# X Y Meaning -# ------------------------------------------------- -# [MD] not updated -# M [ MD] updated in index -# A [ MD] added to index -# D [ M] deleted from index -# R [ MD] renamed in index -# C [ MD] copied in index -# [MARC] index and work tree matches -# [ MARC] M work tree changed since index -# [ MARC] D deleted in work tree -# ------------------------------------------------- -# D D unmerged, both deleted -# A U unmerged, added by us -# U D unmerged, deleted by them -# U A unmerged, added by them -# D U unmerged, deleted by us -# A A unmerged, both added -# U U unmerged, both modified -# ------------------------------------------------- -# ? ? untracked -# ! ! ignored -# ------------------------------------------------- - test_basic_unstaged_options() { status=""" M modified-and-unstaged @@ -41,7 +17,7 @@ test_basic_unstaged_options() { assertEquals "line:${LINENO} staged status failed match" "" "$(staged_status "$status")" assertEquals "line:${LINENO} untracked status failed match" "" "$(untracked_status "$status")" assertEquals "line:${LINENO} unstaged status failed match"\ - "1${unstaged}${deleted}1${unstaged}${modified}" "$(unstaged_status "$status")" + "1D1M" "$(unstaged_status "$status")" assertEquals "line:${LINENO} conflicted status failed match" "" "$(conflicted_status "$status")" } @@ -50,7 +26,7 @@ test_basic_staged_options() { A added-and-staged """ assertEquals "line:${LINENO} staged status failed match"\ - "1${staged}${added}" "$(staged_status "$status")" + "1A" "$(staged_status "$status")" assertEquals "line:${LINENO} untracked status failed match" "" "$(untracked_status "$status")" assertEquals "line:${LINENO} unstaged status failed match" "" "$(unstaged_status "$status")" assertEquals "line:${LINENO} conflicted status failed match" "" "$(conflicted_status "$status")" @@ -59,7 +35,7 @@ A added-and-staged M modified-and-staged """ assertEquals "line:${LINENO} staged status failed match"\ - "1${staged}${modified}" "$(staged_status "$status")" + "1M" "$(staged_status "$status")" assertEquals "line:${LINENO} untracked status failed match" "" "$(untracked_status "$status")" assertEquals "line:${LINENO} unstaged status failed match" "" "$(unstaged_status "$status")" assertEquals "line:${LINENO} conflicted status failed match" "" "$(conflicted_status "$status")" @@ -68,7 +44,7 @@ M modified-and-staged D deleted-and-staged """ assertEquals "line:${LINENO} staged status failed match"\ - "1${staged}${deleted}" "$(staged_status "$status")" + "1D" "$(staged_status "$status")" assertEquals "line:${LINENO} untracked status failed match" "" "$(untracked_status "$status")" assertEquals "line:${LINENO} unstaged status failed match" "" "$(unstaged_status "$status")" assertEquals "line:${LINENO} conflicted status failed match" "" "$(conflicted_status "$status")" @@ -77,7 +53,7 @@ D deleted-and-staged C copied-and-staged """ assertEquals "line:${LINENO} staged status failed match"\ - "1${staged}${copied}" "$(staged_status "$status")" + "1C" "$(staged_status "$status")" assertEquals "line:${LINENO} untracked status failed match" "" "$(untracked_status "$status")" assertEquals "line:${LINENO} unstaged status failed match" "" "$(unstaged_status "$status")" assertEquals "line:${LINENO} conflicted status failed match" "" "$(conflicted_status "$status")" @@ -86,7 +62,7 @@ C copied-and-staged R renamed-and-staged """ assertEquals "line:${LINENO} staged status failed match"\ - "1${staged}${renamed}" "$(staged_status "$status")" + "1R" "$(staged_status "$status")" assertEquals "line:${LINENO} untracked status failed match" "" "$(untracked_status "$status")" assertEquals "line:${LINENO} unstaged status failed match" "" "$(unstaged_status "$status")" assertEquals "line:${LINENO} conflicted status failed match" "" "$(conflicted_status "$status")" @@ -111,7 +87,7 @@ UA unmerged-added-by-them assertEquals "line:${LINENO}" "" "$(staged_status "$status")" assertEquals "line:${LINENO}" "" "$(untracked_status "$status")" assertEquals "line:${LINENO}" "" "$(unstaged_status "$status")" - assertEquals "line:${LINENO}" "2${conflicted}${them}" "$(conflicted_status "$status")" + assertEquals "line:${LINENO}" "2T" "$(conflicted_status "$status")" status=""" AU unmerged-added-by-us @@ -120,7 +96,7 @@ DU unmerged-deleted-by-us assertEquals "line:${LINENO}" "" "$(staged_status "$status")" assertEquals "line:${LINENO}" "" "$(untracked_status "$status")" assertEquals "line:${LINENO}" "" "$(unstaged_status "$status")" - assertEquals "line:${LINENO}" "2${conflicted}${us}" "$(conflicted_status "$status")" + assertEquals "line:${LINENO}" "2U" "$(conflicted_status "$status")" status=""" AA unmerged-both-added @@ -130,7 +106,7 @@ UU unmerged-both-modified assertEquals "line:${LINENO}" "" "$(staged_status "$status")" assertEquals "line:${LINENO}" "" "$(untracked_status "$status")" assertEquals "line:${LINENO}" "" "$(unstaged_status "$status")" - assertEquals "line:${LINENO}" "3${conflicted}${both}" "$(conflicted_status "$status")" + assertEquals "line:${LINENO}" "3B" "$(conflicted_status "$status")" } . ./shunit/shunit2 |