summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Allen <michael@michaelallen.io>2015-02-17 21:09:21 +0000
committerMichael Allen <michael@michaelallen.io>2015-02-17 21:09:58 +0000
commit01538d46bac4d2607ad01d04548085f6918ba4d0 (patch)
tree6d9b963502344d320b9d976108d4d43a7c6ae019
parenta333df6a1a61f0c0e4bc6d774ceff4e9f6bd61f8 (diff)
downloadgit-sonar-01538d46bac4d2607ad01d04548085f6918ba4d0.tar.gz
git-sonar-01538d46bac4d2607ad01d04548085f6918ba4d0.zip
add functions for conflicted changes
-rw-r--r--bar0
-rw-r--r--foo5
-rwxr-xr-xgit-base.sh18
-rwxr-xr-xtest-files.sh124
4 files changed, 147 insertions, 0 deletions
diff --git a/bar b/bar
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bar
diff --git a/foo b/foo
new file mode 100644
index 0000000..1a18f73
--- /dev/null
+++ b/foo
@@ -0,0 +1,5 @@
+
+foo
+
+foo
+bar
diff --git a/git-base.sh b/git-base.sh
index 20388aa..18d3dec 100755
--- a/git-base.sh
+++ b/git-base.sh
@@ -207,3 +207,21 @@ staged_deleted_changes() {
staged_renamed_changes() {
echo "$(count_from_porcelain "$git_status" "R[A|M|C|D|U|R ] ")"
}
+
+unstaged_modified_changes() {
+ echo "$(count_from_porcelain "$git_status" "[A|M|C|D|U|R ]M ")"
+}
+unstaged_deleted_changes() {
+ echo "$(count_from_porcelain "$git_status" "[A|M|C|D|U|R ]D ")"
+}
+
+conflicted_by_us_changes() {
+ echo "$(count_from_porcelain "$git_status" "[A|M|C|D|R ]U ")"
+}
+conflicted_by_them_changes() {
+ echo "$(count_from_porcelain "$git_status" "U[A|M|C|D|R ] ")"
+}
+conflicted_both_changes() {
+ echo "$(count_from_porcelain "$git_status" "UU ")"
+}
+
diff --git a/test-files.sh b/test-files.sh
index 22a1966..1966d03 100755
--- a/test-files.sh
+++ b/test-files.sh
@@ -30,6 +30,46 @@ test_untracked_files() {
rm_tmp
}
+test_unstaged_modified_files() {
+ cd_to_tmp
+ git init --quiet
+
+ assertEquals "0" "$(unstaged_modified_changes)"
+
+ touch foo
+ touch bar
+ git add .
+ git commit -m "foo and bar" >/dev/null
+
+ echo "foo" >> foo
+ assertEquals "1" "$(unstaged_modified_changes)"
+
+ echo "bar" >> bar
+ assertEquals "2" "$(unstaged_modified_changes)"
+
+ rm_tmp
+}
+
+test_unstaged_deleted_files() {
+ cd_to_tmp
+ git init --quiet
+
+ assertEquals "0" "$(unstaged_deleted_changes)"
+
+ touch foo
+ touch bar
+ git add .
+ git commit -m "foo and bar" >/dev/null
+
+ rm foo
+ assertEquals "1" "$(unstaged_deleted_changes)"
+
+ rm bar
+ assertEquals "2" "$(unstaged_deleted_changes)"
+
+ rm_tmp
+}
+
test_staged_added_files() {
cd_to_tmp
git init --quiet
@@ -113,4 +153,88 @@ test_staged_renamed_files() {
rm_tmp
}
+test_conflicted_both_changes() {
+ cd_to_tmp
+ git init --quiet
+
+ git checkout -b foo --quiet
+ echo "foo" >> foo
+ git add .
+ git commit -m "foo" --quiet
+
+ git checkout -b foo2 --quiet
+ echo "bar" >> foo
+ git add .
+ git commit -m "bar" --quiet
+
+ git checkout foo --quiet
+ echo "foo2" >> foo
+ git add .
+ git commit -m "foo2" --quiet
+
+ assertEquals "0" "$(conflicted_both_changes)"
+
+ git merge foo2 >/dev/null
+
+ assertEquals "1" "$(conflicted_both_changes)"
+
+ rm_tmp
+}
+
+test_conflicted_them_changes() {
+ cd_to_tmp
+ git init --quiet
+
+ git checkout -b foo --quiet
+ echo "foo" >> foo
+ git add .
+ git commit -m "foo" --quiet
+
+ git checkout -b foo2 --quiet
+ rm foo
+ git add .
+ git commit -m "delete foo" --quiet
+
+ git checkout foo --quiet
+ echo "foo2" >> foo
+ git add .
+ git commit -m "foo2" --quiet
+
+ assertEquals "0" "$(conflicted_by_them_changes)"
+
+ git merge foo2 >/dev/null
+
+ assertEquals "1" "$(conflicted_by_them_changes)"
+
+ rm_tmp
+}
+
+test_conflicted_us_changes() {
+ cd_to_tmp
+ git init --quiet
+
+ git checkout -b foo --quiet
+ echo "foo" >> foo
+ git add .
+ git commit -m "foo" --quiet
+
+ git checkout -b foo2 --quiet
+ echo "bar" >> foo
+ git add .
+ git commit -m "bar" --quiet
+
+ git checkout foo --quiet
+ rm foo
+ git add .
+ git commit -m "delete foo" --quiet
+
+ assertEquals "0" "$(conflicted_by_us_changes)"
+
+ git merge foo2 >/dev/null
+
+ assertEquals "1" "$(conflicted_by_us_changes)"
+
+ rm_tmp
+}
+
. ./shunit/shunit2