summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Allen <michael@michaelallen.io>2015-03-02 00:42:42 +0000
committerMichael Allen <michael@michaelallen.io>2015-03-02 00:42:42 +0000
commitd1d362fb8cf03263d259d91215b841c4aea2ac50 (patch)
tree23bf7582a0ea8b7c98fe817d4affbada51a7c47e
parent921c0d804fd235ef19c3b191696425d7b55738e4 (diff)
downloadgit-sonar-d1d362fb8cf03263d259d91215b841c4aea2ac50.tar.gz
git-sonar-d1d362fb8cf03263d259d91215b841c4aea2ac50.zip
speed up remote_behind/ahead by not checking if tracking = remote
-rwxr-xr-xgit-base.sh6
-rwxr-xr-xtest-commits.sh25
2 files changed, 29 insertions, 2 deletions
diff --git a/git-base.sh b/git-base.sh
index cf67198..a110056 100755
--- a/git-base.sh
+++ b/git-base.sh
@@ -165,7 +165,8 @@ commits_ahead_of_remote() {
remote_behind_of_master() {
remote_branch=${1:-"$(remote_branch_name)"}
- if [[ -n "$remote_branch" ]]; then
+ tracked_remote="origin/master"
+ if [[ -n "$remote_branch" && "$remote_branch" != "$tracked_remote" ]]; then
set --
set -- $(git rev-list --left-right --count origin/master...${remote_branch})
behind=$1
@@ -179,7 +180,8 @@ remote_behind_of_master() {
remote_ahead_of_master() {
remote_branch=${1:-"$(remote_branch_name)"}
- if [[ -n "$remote_branch" ]]; then
+ tracked_remote="origin/master"
+ if [[ -n "$remote_branch" && "$remote_branch" != "$tracked_remote" ]]; then
set --
set -- $(git rev-list --left-right --count origin/master...${remote_branch})
behind=$1
diff --git a/test-commits.sh b/test-commits.sh
index e3c945b..e1800aa 100755
--- a/test-commits.sh
+++ b/test-commits.sh
@@ -234,4 +234,29 @@ test_dont_call_remote_branch_name() {
rm_tmp
}
+test_dont_remote_if_remote_is_master() {
+ cd_to_tmp
+ git init --quiet
+
+ remote_branch="origin/master"
+
+ debug_output="$(
+ {
+ set -x
+ output="$(
+ remote_behind_of_master "$remote_branch";
+ remote_ahead_of_master "$remote_branch";
+ )"
+ set +x
+ } 2>&1
+ echo "$output"
+ )"
+
+ usages="$(echo "$debug_output" | grep 'git rev-list' | wc -l )"
+
+ assertEquals " 0" "$usages"
+
+ rm_tmp
+}
+
. ./shunit/shunit2