summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rwxr-xr-xradar-base.sh28
-rwxr-xr-xtest-colors.sh4
-rwxr-xr-xtest-files.sh2
-rwxr-xr-xtest-format-config.sh220
-rwxr-xr-xtest-status.sh2
6 files changed, 142 insertions, 119 deletions
diff --git a/README.md b/README.md
index 2f4e39f..91f87cd 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,7 @@ last few years. Maybe it can help you too.
- [Colouring the remote commits status](#colouring-the-remote-commits-status)
- [Colouring the file changes status](#colouring-the-file-changes-status)
- [License](#license)
+- [Links](#links)
## Installation
@@ -557,6 +558,10 @@ Git Radar is licensed under the MIT license.
See [LICENSE] for the full license text.
+## Links
+
+* [mini-git-radar](https://github.com/bogem/mini-git-radar) - lightweight version of git-radar. Only for macOS and bash/fish.
+
[LICENSE]: https://github.com/michaeldfallen/git-radar/blob/master/LICENSE
[git:(master) 1≡]: https://raw.githubusercontent.com/michaeldfallen/git-radar/master/images/stash.png
[git:(master) 3A]: https://raw.githubusercontent.com/michaeldfallen/git-radar/master/images/untracked.png
diff --git a/radar-base.sh b/radar-base.sh
index b5a7df9..649978f 100755
--- a/radar-base.sh
+++ b/radar-base.sh
@@ -264,9 +264,19 @@ commits_ahead_of_remote() {
fi
}
+determine_tracked_remote() {
+ by_branch=$(git config --local branch."$(git rev-parse --abbrev-ref HEAD)".git-radar-tracked-remote)
+ [[ ! -z $by_branch ]] && echo $by_branch && return 0
+
+ by_config=$(git config --local git-radar.tracked-remote)
+ [[ ! -z $by_config ]] && echo $by_config && return 0
+
+ echo "origin/master"
+}
+
remote_behind_of_master() {
remote_branch=${1:-"$(remote_branch_name)"}
- tracked_remote="origin/master"
+ tracked_remote=$(determine_tracked_remote)
if [[ -n "$remote_branch" && "$remote_branch" != "$tracked_remote" ]]; then
git rev-list --left-only --count ${tracked_remote}...${remote_branch} 2>/dev/null || printf '%s' "0"
else
@@ -276,7 +286,7 @@ remote_behind_of_master() {
remote_ahead_of_master() {
remote_branch=${1:-"$(remote_branch_name)"}
- tracked_remote="origin/master"
+ tracked_remote=$(determine_tracked_remote)
if [[ -n "$remote_branch" && "$remote_branch" != "$tracked_remote" ]]; then
git rev-list --right-only --count ${tracked_remote}...${remote_branch} 2>/dev/null || printf '%s' "0"
else
@@ -337,6 +347,7 @@ staged_status() {
local filesDeleted="$(printf '%s' "$gitStatus" | grep -oE "D[AMCR ] " | wc -l | grep -oEi '[1-9][0-9]*')"
local filesRenamed="$(printf '%s' "$gitStatus" | grep -oE "R[AMCD ] " | wc -l | grep -oEi '[1-9][0-9]*')"
local filesCopied="$(printf '%s' "$gitStatus" | grep -oE "C[AMDR ] " | wc -l | grep -oEi '[1-9][0-9]*')"
+ local typeChanged="$(printf '%s' "$gitStatus" | grep -oE "T[AMDR ] " | wc -l | grep -oEi '[1-9][0-9]*')"
if [ -n "$filesAdded" ]; then
staged_string="$staged_string$filesAdded${prefix}A${suffix}"
@@ -353,6 +364,9 @@ staged_status() {
if [ -n "$filesCopied" ]; then
staged_string="$staged_string$filesCopied${prefix}C${suffix}"
fi
+ if [ -n "$typeChanged" ]; then
+ staged_string="$staged_string$typeChanged${prefix}TC${suffix}"
+ fi
printf '%s' "$staged_string"
}
@@ -386,6 +400,7 @@ unstaged_status() {
local filesModified="$(printf '%s' "$gitStatus" | grep -oE "[ACDRM ]M " | wc -l | grep -oEi '[1-9][0-9]*')"
local filesDeleted="$(printf '%s' "$gitStatus" | grep -oE "[AMCR ]D " | wc -l | grep -oEi '[1-9][0-9]*')"
+ local typeChanged="$(printf '%s' "$gitStatus" | grep -oE "[AMDR ]T " | wc -l | grep -oEi '[1-9][0-9]*')"
if [ -n "$filesDeleted" ]; then
unstaged_string="$unstaged_string$filesDeleted${prefix}D${suffix}"
@@ -393,6 +408,9 @@ unstaged_status() {
if [ -n "$filesModified" ]; then
unstaged_string="$unstaged_string$filesModified${prefix}M${suffix}"
fi
+ if [ -n "$typeChanged" ]; then
+ unstaged_string="$unstaged_string$typeChanged${prefix}TC${suffix}"
+ fi
printf '%s' "$unstaged_string"
}
@@ -405,7 +423,7 @@ untracked_status() {
local filesUntracked="$(printf '%s' "$gitStatus" | grep "?? " | wc -l | grep -oEi '[1-9][0-9]*')"
if [ -n "$filesUntracked" ]; then
- untracked_string="$untracked_string$filesUntracked${prefix}A${suffix}"
+ untracked_string="$untracked_string$filesUntracked${prefix}?${suffix}"
fi
printf '%s' "$untracked_string"
}
@@ -542,12 +560,12 @@ is_cwd_a_dot_git_directory() {
elif [[ -z $1 ]]; then
return 1
else
- is_cwd_a_dot_git_directory ${1%/*}
+ is_cwd_a_dot_git_directory "${1%/*}"
fi
}
stash_status() {
- if ! is_cwd_a_dot_git_directory $PWD; then
+ if ! is_cwd_a_dot_git_directory "$PWD"; then
local number_stashes="$(stashed_status)"
if [ $number_stashes -gt 0 ]; then
printf $PRINT_F_OPTION "${number_stashes}${COLOR_STASH}≡${RESET_COLOR_STASH}"
diff --git a/test-colors.sh b/test-colors.sh
index 8cc072b..927dab3 100755
--- a/test-colors.sh
+++ b/test-colors.sh
@@ -459,7 +459,7 @@ test_bash_colors_changes() {
touch bar
git add bar
echo "bar" > bar
- untracked="1\x01changes-untracked\x02A\x01change-reset\x02"
+ untracked="1\x01changes-untracked\x02?\x01change-reset\x02"
unstaged="1\x01changes-unstaged\x02M\x01change-reset\x02"
staged="1\x01changes-staged\x02A\x01change-reset\x02"
@@ -481,7 +481,7 @@ test_zsh_colors_changes() {
touch bar
git add bar
echo "bar" > bar
- untracked="1%{changes-untracked%}A%{change-reset%}"
+ untracked="1%{changes-untracked%}?%{change-reset%}"
unstaged="1%{changes-unstaged%}M%{change-reset%}"
staged="1%{changes-staged%}A%{change-reset%}"
diff --git a/test-files.sh b/test-files.sh
index 8f46edf..b27a18c 100755
--- a/test-files.sh
+++ b/test-files.sh
@@ -22,7 +22,7 @@ test_untracked_files() {
assertEquals "" "$(untracked_status)"
touch foo
- assertEquals "1A" "$(untracked_status)"
+ assertEquals "1?" "$(untracked_status)"
git add .
assertEquals "" "$(untracked_status)"
diff --git a/test-format-config.sh b/test-format-config.sh
index 72ac60d..c5852e5 100755
--- a/test-format-config.sh
+++ b/test-format-config.sh
@@ -91,28 +91,28 @@ test_all_options_set_config() {
unset_colours
prompt="$(render_prompt)"
- assertEquals "$prompt" "m 1 →foo1↑1A"
+ assertEquals "$prompt" "m 1 →foo1↑1?"
export GIT_RADAR_FORMAT="%{remote}%{branch}%{changes}"
prepare_zsh_colors
unset_colours
prompt="$(render_prompt)"
- assertEquals "$prompt" "m 1 →foo1A"
+ assertEquals "$prompt" "m 1 →foo1?"
export GIT_RADAR_FORMAT="%{branch}%{local}%{changes}"
prepare_zsh_colors
unset_colours
prompt="$(render_prompt)"
- assertEquals "$prompt" "foo1↑1A"
+ assertEquals "$prompt" "foo1↑1?"
export GIT_RADAR_FORMAT="%{branch}%{changes}"
prepare_zsh_colors
unset_colours
prompt="$(render_prompt)"
- assertEquals "$prompt" "foo1A"
+ assertEquals "$prompt" "foo1?"
export GIT_RADAR_FORMAT="%{branch}"
prepare_zsh_colors
@@ -124,111 +124,111 @@ test_all_options_set_config() {
rm_tmp
}
-#test_reorder_parts() {
-# prepare_test_repo
-#
-# export GIT_RADAR_FORMAT="%{branch}%{local}%{changes}%{remote}"
-# prepare_zsh_colors
-# unset_colours
-#
-# prompt="$(render_prompt)"
-# assertEquals "foo1↑1Am 1 →" "$prompt"
-#
-# export GIT_RADAR_FORMAT="%{local}%{changes}%{remote}%{branch}"
-# prepare_zsh_colors
-# unset_colours
-#
-# prompt="$(render_prompt)"
-# assertEquals "1↑1Am 1 →foo" "$prompt"
-#
-# export GIT_RADAR_FORMAT="%{changes}%{remote}%{branch}%{local}"
-# prepare_zsh_colors
-# unset_colours
-#
-# prompt="$(render_prompt)"
-# assertEquals "1Am 1 →foo1↑" "$prompt"
-#
-# rm_tmp
-#}
-#
-#test_prefix_and_suffix_changes() {
-# prepare_test_repo
-#
-# export GIT_RADAR_FORMAT="%{changes}"
-# prepare_zsh_colors
-# unset_colours
-#
-# prompt="$(render_prompt)"
-# assertEquals "1A" "$prompt"
-#
-# export GIT_RADAR_FORMAT="%{[:changes:]}"
-# prepare_zsh_colors
-# unset_colours
-#
-# prompt="$(render_prompt)"
-# assertEquals "[1A]" "$prompt"
-#
-# rm_tmp
-#}
-#
-#test_prefix_and_suffix_local() {
-# prepare_test_repo
-#
-# export GIT_RADAR_FORMAT="%{local}"
-# prepare_zsh_colors
-# unset_colours
-#
-# prompt="$(render_prompt)"
-# assertEquals "1↑" "$prompt"
-#
-# export GIT_RADAR_FORMAT="%{[:local:]}"
-# prepare_zsh_colors
-# unset_colours
-#
-# prompt="$(render_prompt)"
-# assertEquals "[1↑]" "$prompt"
-#
-# rm_tmp
-#}
-#
-#test_prefix_and_suffix_branch() {
-# prepare_test_repo
-#
-# export GIT_RADAR_FORMAT="%{branch}"
-# prepare_zsh_colors
-# unset_colours
-#
-# prompt="$(render_prompt)"
-# assertEquals "foo" "$prompt"
-#
-# export GIT_RADAR_FORMAT="%{[:branch:]}"
-# prepare_zsh_colors
-# unset_colours
-#
-# prompt="$(render_prompt)"
-# assertEquals "[foo]" "$prompt"
-#
-# rm_tmp
-#}
-#
-#test_prefix_and_suffix_remote() {
-# prepare_test_repo
-#
-# export GIT_RADAR_FORMAT="%{remote}"
-# prepare_zsh_colors
-# unset_colours
-#
-# prompt="$(render_prompt)"
-# assertEquals "m 1 →" "$prompt"
-#
-# export GIT_RADAR_FORMAT="%{[:remote:]}"
-# prepare_zsh_colors
-# unset_colours
-#
-# prompt="$(render_prompt)"
-# assertEquals "[m 1 →]" "$prompt"
-#
-# rm_tmp
-#}
+test_reorder_parts() {
+ prepare_test_repo
+
+ export GIT_RADAR_FORMAT="%{branch}%{local}%{changes}%{remote}"
+ prepare_zsh_colors
+ unset_colours
+
+ prompt="$(render_prompt)"
+ assertEquals "foo1↑1?m 1 →" "$prompt"
+
+ export GIT_RADAR_FORMAT="%{local}%{changes}%{remote}%{branch}"
+ prepare_zsh_colors
+ unset_colours
+
+ prompt="$(render_prompt)"
+ assertEquals "1↑1?m 1 →foo" "$prompt"
+
+ export GIT_RADAR_FORMAT="%{changes}%{remote}%{branch}%{local}"
+ prepare_zsh_colors
+ unset_colours
+
+ prompt="$(render_prompt)"
+ assertEquals "1?m 1 →foo1↑" "$prompt"
+
+ rm_tmp
+}
+
+test_prefix_and_suffix_changes() {
+ prepare_test_repo
+
+ export GIT_RADAR_FORMAT="%{changes}"
+ prepare_zsh_colors
+ unset_colours
+
+ prompt="$(render_prompt)"
+ assertEquals "1?" "$prompt"
+
+ export GIT_RADAR_FORMAT="%{[:changes:]}"
+ prepare_zsh_colors
+ unset_colours
+
+ prompt="$(render_prompt)"
+ assertEquals "[1?]" "$prompt"
+
+ rm_tmp
+}
+
+test_prefix_and_suffix_local() {
+ prepare_test_repo
+
+ export GIT_RADAR_FORMAT="%{local}"
+ prepare_zsh_colors
+ unset_colours
+
+ prompt="$(render_prompt)"
+ assertEquals "1↑" "$prompt"
+
+ export GIT_RADAR_FORMAT="%{[:local:]}"
+ prepare_zsh_colors
+ unset_colours
+
+ prompt="$(render_prompt)"
+ assertEquals "[1↑]" "$prompt"
+
+ rm_tmp
+}
+
+test_prefix_and_suffix_branch() {
+ prepare_test_repo
+
+ export GIT_RADAR_FORMAT="%{branch}"
+ prepare_zsh_colors
+ unset_colours
+
+ prompt="$(render_prompt)"
+ assertEquals "foo" "$prompt"
+
+ export GIT_RADAR_FORMAT="%{[:branch:]}"
+ prepare_zsh_colors
+ unset_colours
+
+ prompt="$(render_prompt)"
+ assertEquals "[foo]" "$prompt"
+
+ rm_tmp
+}
+
+test_prefix_and_suffix_remote() {
+ prepare_test_repo
+
+ export GIT_RADAR_FORMAT="%{remote}"
+ prepare_zsh_colors
+ unset_colours
+
+ prompt="$(render_prompt)"
+ assertEquals "m 1 →" "$prompt"
+
+ export GIT_RADAR_FORMAT="%{[:remote:]}"
+ prepare_zsh_colors
+ unset_colours
+
+ prompt="$(render_prompt)"
+ assertEquals "[m 1 →]" "$prompt"
+
+ rm_tmp
+}
. ./shunit/shunit2
diff --git a/test-status.sh b/test-status.sh
index 8c6bf89..7378986 100755
--- a/test-status.sh
+++ b/test-status.sh
@@ -30,7 +30,7 @@ UU modified-both-conflicted
assertEquals "line:${LINENO}" "1_U-1_T-1_B-"\
"$(conflicted_status "$status" "$prefix" "$suffix")"
- assertEquals "line:${LINENO}" "1_A-"\
+ assertEquals "line:${LINENO}" "1_?-"\
"$(untracked_status "$status" "$prefix" "$suffix")"
}