summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgit-base.sh8
-rwxr-xr-xtest-commits.sh49
2 files changed, 51 insertions, 6 deletions
diff --git a/git-base.sh b/git-base.sh
index 7ffb511..a4680c6 100755
--- a/git-base.sh
+++ b/git-base.sh
@@ -140,7 +140,7 @@ remote_branch_name() {
}
commits_behind_of_remote() {
- remote_branch="$(remote_branch_name)"
+ remote_branch=${1:-"$(remote_branch_name)"}
if [[ -n "$remote_branch" ]]; then
set --
set -- $(git rev-list --left-right --count ${remote_branch}...HEAD)
@@ -154,7 +154,7 @@ commits_behind_of_remote() {
}
commits_ahead_of_remote() {
- remote_branch="$(remote_branch_name)"
+ remote_branch=${1:-"$(remote_branch_name)"}
if [[ -n "$remote_branch" ]]; then
set --
set -- $(git rev-list --left-right --count ${remote_branch}...HEAD)
@@ -168,7 +168,7 @@ commits_ahead_of_remote() {
}
remote_behind_of_master() {
- remote_branch="$(remote_branch_name)"
+ remote_branch=${1:-"$(remote_branch_name)"}
if [[ -n "$remote_branch" ]]; then
set --
set -- $(git rev-list --left-right --count origin/master...${remote_branch})
@@ -182,7 +182,7 @@ remote_behind_of_master() {
}
remote_ahead_of_master() {
- remote_branch="$(remote_branch_name)"
+ remote_branch=${1:-"$(remote_branch_name)"}
if [[ -n "$remote_branch" ]]; then
set --
set -- $(git rev-list --left-right --count origin/master...${remote_branch})
diff --git a/test-commits.sh b/test-commits.sh
index 28885e3..e3c945b 100755
--- a/test-commits.sh
+++ b/test-commits.sh
@@ -162,8 +162,8 @@ test_remote_behind_master() {
touch README
git add README
git commit -m "initial commit" --quiet
-
- git push --quiet -u origin master >/dev/null
+
+ git push --quiet -u origin master >/dev/null
git reset --quiet --hard HEAD
git checkout -b foo --quiet
@@ -189,4 +189,49 @@ test_remote_behind_master() {
rm_tmp
}
+test_dont_call_remote_branch_name() {
+ cd_to_tmp "remote"
+ git init --bare --quiet
+ remoteLocation="$(pwd)"
+
+ cd_to_tmp "new"
+ git init --quiet
+ git remote add origin $remoteLocation
+ git fetch origin --quiet
+ git checkout -b master --quiet
+ touch README
+ git add README
+ git commit -m "initial commit" --quiet
+
+ git push --quiet -u origin master >/dev/null
+ git reset --quiet --hard HEAD
+
+ git checkout -b foo --quiet
+ git push --quiet -u origin foo >/dev/null
+
+ remote_branch="$(remote_branch_name)"
+
+ debug_output="$(
+ {
+ set -x
+ output="$(
+ remote_behind_of_master "$remote_branch";
+ remote_ahead_of_master "$remote_branch";
+ commits_ahead_of_remote "$remote_branch";
+ commits_behind_of_remote "$remote_branch";
+ )"
+ set +x
+ } 2>&1
+ echo "$output"
+ )"
+
+ #Grep through the output and look for remote_branch_name being called
+ usages="$(echo "$debug_output" | grep 'remote_branch_name' | wc -l )"
+
+ #wc -l has a weird output
+ assertEquals " 0" "$usages"
+
+ rm_tmp
+}
+
. ./shunit/shunit2