diff options
author | Michael Allen <michael@michaelallen.io> | 2015-02-12 16:53:08 +0000 |
---|---|---|
committer | Michael Allen <michael@michaelallen.io> | 2015-02-12 16:53:08 +0000 |
commit | 43ac2a587f9b0b218875e3f1aa5a68ed4f1f8f19 (patch) | |
tree | a7557b5d64beab088a919562a359e72d925c3726 /test-commits.sh | |
parent | 8d7c08e7f0d1fd880345cf4c62b0568e509ce13a (diff) | |
download | git-sonar-43ac2a587f9b0b218875e3f1aa5a68ed4f1f8f19.tar.gz git-sonar-43ac2a587f9b0b218875e3f1aa5a68ed4f1f8f19.zip |
find branch names and commits ahead or behind
Diffstat (limited to '')
-rwxr-xr-x | test-commits.sh | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/test-commits.sh b/test-commits.sh new file mode 100755 index 0000000..003ebbf --- /dev/null +++ b/test-commits.sh @@ -0,0 +1,118 @@ +scriptDir="$(cd "$(dirname "$0")"; pwd)" + +source "$scriptDir/git-base.sh" + +tmpfile="" + +cd_to_tmp() { + tmpfile="/tmp/git-prompt-tests-$(time_now)$1" + mkdir -p "$tmpfile" + cd "$tmpfile" +} + +rm_tmp() { + cd $scriptDir + rm -rf /tmp/git-prompt-tests* +} + +test_commits_with_no_commits() { + cd_to_tmp + git init --quiet + + assertEquals "0" "$(commits_ahead_of_remote)" + assertEquals "0" "$(commits_behind_of_remote)" + + rm_tmp +} + +test_commits_behind_no_remote() { + cd_to_tmp + git init --quiet + + echo "foo" > foo + git add . + git commit -m "test commit" --quiet + assertEquals "0" "$(commits_behind_of_remote)" + + rm_tmp +} + +test_commits_ahead_no_remote() { + cd_to_tmp + git init --quiet + + echo "foo" > foo + git add . + git commit -m "test commit" --quiet + assertEquals "0" "$(commits_ahead_of_remote)" + + echo "bar" > bar + git add . + git commit -m "test commit" --quiet + assertEquals "0" "$(commits_ahead_of_remote)" + + rm_tmp +} + +test_commits_ahead_with_remote() { + cd_to_tmp "remote" + git init --quiet + touch README + git add . + git commit -m "initial commit" --quiet + remoteLocation="$(pwd)" + + cd_to_tmp "new" + git init --quiet + git remote add origin $remoteLocation + git fetch origin --quiet + git checkout master --quiet + repoLocation="$(pwd)" + + cd "$remoteLocation" + echo "foo" > foo + git add . + git commit -m "test commit" --quiet + cd "$repoLocation" + git fetch origin --quiet + assertEquals "1" "$(commits_ahead_of_remote)" + + cd "$remoteLocation" + echo "bar" > bar + git add . + git commit -m "test commit" --quiet + cd "$repoLocation" + git fetch origin --quiet + assertEquals "2" "$(commits_ahead_of_remote)" + + rm_tmp +} + +test_commits_ahead_with_remote() { + cd_to_tmp "remote" + git init --quiet + touch README + git add . + git commit -m "initial commit" --quiet + remoteLocation="$(pwd)" + + cd_to_tmp "new" + git init --quiet + git remote add origin $remoteLocation + git fetch origin --quiet + git checkout master --quiet + + echo "foo" > foo + git add . + git commit -m "test commit" --quiet + assertEquals "1" "$(commits_ahead_of_remote)" + + echo "bar" > bar + git add . + git commit -m "test commit" --quiet + assertEquals "2" "$(commits_ahead_of_remote)" + + rm_tmp +} + +. ./shunit/shunit2 |