diff options
| author | Matt Hunter <m@lfurio.us> | 2026-03-08 14:45:31 -0400 |
|---|---|---|
| committer | Matt Hunter <m@lfurio.us> | 2026-03-16 04:36:28 -0400 |
| commit | 62c225c40ffebcd3c35f3a9917f1a4dff4b81137 (patch) | |
| tree | 6121589ff1c8d0ebc9d88b92b8fae822d5627b27 | |
| parent | 08ad67de221f737457cb8efc9bf02707d2aca549 (diff) | |
| download | git-sonar-62c225c40ffebcd3c35f3a9917f1a4dff4b81137.tar.gz git-sonar-62c225c40ffebcd3c35f3a9917f1a4dff4b81137.zip | |
Remove [[ ]] tests
Tests using the `[[ ]]` syntax are not supported in POSIX-compliant
shell. Remove the rest of these cases which more directly translate to
standard tests. Some small cleanups are made along the way.
Signed-off-by: Matt Hunter <m@lfurio.us>
| -rwxr-xr-x | git-sonar | 54 |
1 files changed, 27 insertions, 27 deletions
@@ -72,11 +72,11 @@ remote_branch_name() { local localRef local remote localRef="$(branch_name)" - remote="$(git config --get "branch.$localRef.remote")" - if [[ -n $remote ]]; then + remote="$(git config --get "branch.${localRef}.remote")" + if [ -n "$remote" ]; then local remoteBranch remoteBranch="$(git config --get "branch.${localRef}.merge" | sed -e 's/^refs\/heads\///')" - if [[ -n $remoteBranch ]]; then + if [ -n "$remoteBranch" ]; then printf '%s/%s' "$remote" "$remoteBranch" return 0 else @@ -89,7 +89,7 @@ remote_branch_name() { commits_behind_of_remote() { remote_branch=${1:-"$(remote_branch_name)"} - if [[ -n "$remote_branch" ]]; then + if [ -n "$remote_branch" ]; then git rev-list --left-only --count "${remote_branch}...HEAD" 2>/dev/null else printf '%s' "0" @@ -98,7 +98,7 @@ commits_behind_of_remote() { commits_ahead_of_remote() { remote_branch=${1:-"$(remote_branch_name)"} - if [[ -n "$remote_branch" ]]; then + if [ -n "$remote_branch" ]; then git rev-list --right-only --count "${remote_branch}...HEAD" 2>/dev/null else printf '%s' "0" @@ -107,10 +107,10 @@ commits_ahead_of_remote() { 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 + [ -n "$by_branch" ] && echo "$by_branch" && return 0 by_config=$(git config --local git-radar.tracked-remote) - [[ ! -z "$by_config" ]] && echo "$by_config" && return 0 + [ -n "$by_config" ] && echo "$by_config" && return 0 echo "origin/master" } @@ -118,7 +118,7 @@ determine_tracked_remote() { remote_behind_of_master() { remote_branch=${1:-"$(remote_branch_name)"} tracked_remote=$(determine_tracked_remote) - if [[ -n "$remote_branch" && "$remote_branch" != "$tracked_remote" ]]; then + 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 printf '%s' "0" @@ -128,7 +128,7 @@ remote_behind_of_master() { remote_ahead_of_master() { remote_branch=${1:-"$(remote_branch_name)"} tracked_remote=$(determine_tracked_remote) - if [[ -n "$remote_branch" && "$remote_branch" != "$tracked_remote" ]]; then + 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 printf '%s' "0" @@ -256,7 +256,7 @@ color_changes_status() { porcelain="$(porcelain_status)" local changes="" - if [[ -n "$porcelain" ]]; then + if [ -n "$porcelain" ]; then local staged_changes local unstaged_changes local untracked_changes @@ -265,19 +265,19 @@ color_changes_status() { unstaged_changes="$(unstaged_status "$porcelain" "$COLOR_CHANGES_UNSTAGED" "$RESET_COLOR_CHANGES")" untracked_changes="$(untracked_status "$porcelain" "$COLOR_CHANGES_UNTRACKED" "$RESET_COLOR_CHANGES")" conflicted_changes="$(conflicted_status "$porcelain" "$COLOR_CHANGES_CONFLICTED" "$RESET_COLOR_CHANGES")" - if [[ -n "$staged_changes" ]]; then + if [ -n "$staged_changes" ]; then staged_changes="$separator$staged_changes" fi - if [[ -n "$unstaged_changes" ]]; then + if [ -n "$unstaged_changes" ]; then unstaged_changes="$separator$unstaged_changes" fi - if [[ -n "$conflicted_changes" ]]; then + if [ -n "$conflicted_changes" ]; then conflicted_changes="$separator$conflicted_changes" fi - if [[ -n "$untracked_changes" ]]; then + if [ -n "$untracked_changes" ]; then untracked_changes="$separator$untracked_changes" fi @@ -296,11 +296,11 @@ color_local_commits() { local_ahead="$(commits_ahead_of_remote "$remote_branch")" local_behind="$(commits_behind_of_remote "$remote_branch")" - if [[ "$local_behind" -gt "0" && "$local_ahead" -gt "0" ]]; then + if [ "$local_behind" -gt 0 ] && [ "$local_ahead" -gt 0 ]; then local_commits="$local_behind$yellow_diverged_arrow$local_ahead" - elif [[ "$local_behind" -gt "0" ]]; then + elif [ "$local_behind" -gt 0 ]; then local_commits="$local_behind$red_behind_arrow" - elif [[ "$local_ahead" -gt "0" ]]; then + elif [ "$local_ahead" -gt 0 ]; then local_commits="$local_ahead$green_ahead_arrow" fi fi @@ -327,11 +327,11 @@ color_remote_commits() { remote_ahead="$(remote_ahead_of_master "$remote_branch")" remote_behind="$(remote_behind_of_master "$remote_branch")" - if [[ "$remote_behind" -gt "0" && "$remote_ahead" -gt "0" ]]; then + if [ "$remote_behind" -gt 0 ] && [ "$remote_ahead" -gt 0 ]; then remote="$MASTER_SYMBOL$remote_behind$yellow_diverged_arrow$remote_ahead" - elif [[ "$remote_ahead" -gt "0" ]]; then + elif [ "$remote_ahead" -gt 0 ]; then remote="$MASTER_SYMBOL$green_ahead_arrow$remote_ahead" - elif [[ "$remote_behind" -gt "0" ]]; then + elif [ "$remote_behind" -gt 0 ]; then remote="$MASTER_SYMBOL$remote_behind$red_behind_arrow" fi fi @@ -375,7 +375,7 @@ render_prompt() { if echo "$PROMPT_FORMAT" | grep -qE "${if_pre}condition${if_post}"; then condition_result="$(repo_special_condition)" - if [[ -n "$condition_result" ]]; then + if [ -n "$condition_result" ]; then condition_sed="s/${sed_pre}condition${sed_post}/\2${condition_result}\4/" else condition_sed="s/${sed_pre}condition${sed_post}//" @@ -383,7 +383,7 @@ render_prompt() { fi if echo "$PROMPT_FORMAT" | grep -qE "${if_pre}missingups${if_post}"; then missingups_result="$(color_missing_upstream)" - if [[ -n "$missingups_result" ]]; then + if [ -n "$missingups_result" ]; then missingups_sed="s/${sed_pre}missingups${sed_post}/\2${missingups_result}\4/" else missingups_sed="s/${sed_pre}missingups${sed_post}//" @@ -391,7 +391,7 @@ render_prompt() { fi if echo "$PROMPT_FORMAT" | grep -qE "${if_pre}remote${if_post}"; then remote_result="$(color_remote_commits)" - if [[ -n "$remote_result" ]]; then + if [ -n "$remote_result" ]; then remote_sed="s/${sed_pre}remote${sed_post}/\2${remote_result}\4/" else remote_sed="s/${sed_pre}remote${sed_post}//" @@ -399,7 +399,7 @@ render_prompt() { fi if echo "$PROMPT_FORMAT" | grep -qE "${if_pre}branch${if_post}"; then branch_result="$(readable_branch_name | sed -e 's/\//\\\//g')" - if [[ -n "$branch_result" ]]; then + if [ -n "$branch_result" ]; then branch_sed="s/${sed_pre}branch${sed_post}/\2${branch_result}\4/" else branch_sed="s/${sed_pre}branch${sed_post}//" @@ -407,7 +407,7 @@ render_prompt() { fi if echo "$PROMPT_FORMAT" | grep -qE "${if_pre}local${if_post}"; then local_result="$(color_local_commits)" - if [[ -n "$local_result" ]]; then + if [ -n "$local_result" ]; then local_sed="s/${sed_pre}local${sed_post}/\2$local_result\4/" else local_sed="s/${sed_pre}local${sed_post}//" @@ -415,7 +415,7 @@ render_prompt() { fi if echo "$PROMPT_FORMAT" | grep -qE "${if_pre}changes${if_post}"; then changes_result="$(color_changes_status)" - if [[ -n "$changes_result" ]]; then + if [ -n "$changes_result" ]; then changes_sed="s/${sed_pre}changes${sed_post}/\2${changes_result}\4/" else changes_sed="s/${sed_pre}changes${sed_post}//" @@ -423,7 +423,7 @@ render_prompt() { fi if echo "$PROMPT_FORMAT" | grep -qE "${if_pre}stash${if_post}"; then stash_result="$(stash_status)" - if [[ -n "$stash_result" ]]; then + if [ -n "$stash_result" ]; then stash_sed="s/${sed_pre}stash${sed_post}/\2${stash_result}\4/" else stash_sed="s/${sed_pre}stash${sed_post}//" |
