summaryrefslogtreecommitdiff
path: root/t/t4068-diff-symmetric-merge-base.sh
diff options
context:
space:
mode:
authorDenton Liu <liu.denton@gmail.com>2020-09-20 11:22:25 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-09-21 04:30:26 (GMT)
commit0f5a1d449b9538c2765de9d6683abbb83a7fb4e2 (patch)
tree29cbd67c4138aed23542fb1030c3c718bba6ae9e /t/t4068-diff-symmetric-merge-base.sh
parentdf7dbab881c1aa697f0826d8d00f73d43815acf5 (diff)
downloadgit-0f5a1d449b9538c2765de9d6683abbb83a7fb4e2.zip
git-0f5a1d449b9538c2765de9d6683abbb83a7fb4e2.tar.gz
git-0f5a1d449b9538c2765de9d6683abbb83a7fb4e2.tar.bz2
builtin/diff-index: learn --merge-base
There is currently no easy way to take the diff between the working tree or index and the merge base between an arbitrary commit and HEAD. Even diff's `...` notation doesn't allow this because it only works between commits. However, the ability to do this would be desirable to a user who would like to see all the changes they've made on a branch plus uncommitted changes without taking into account changes made in the upstream branch. Teach diff-index and diff (with one commit) the --merge-base option which allows a user to use the merge base of a commit and HEAD as the "before" side. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t4068-diff-symmetric-merge-base.sh')
-rwxr-xr-xt/t4068-diff-symmetric-merge-base.sh59
1 files changed, 59 insertions, 0 deletions
diff --git a/t/t4068-diff-symmetric-merge-base.sh b/t/t4068-diff-symmetric-merge-base.sh
index bd4cf25..4943237 100755
--- a/t/t4068-diff-symmetric-merge-base.sh
+++ b/t/t4068-diff-symmetric-merge-base.sh
@@ -97,4 +97,63 @@ test_expect_success 'diff --merge-base with three commits' '
test_i18ngrep "usage" err
'
+for cmd in diff-index diff
+do
+ test_expect_success "$cmd --merge-base with one commit" '
+ git checkout master &&
+ git $cmd commit-C >expect &&
+ git $cmd --merge-base br2 >actual &&
+ test_cmp expect actual
+ '
+
+ test_expect_success "$cmd --merge-base with one commit and unstaged changes" '
+ git checkout master &&
+ test_when_finished git reset --hard &&
+ echo unstaged >>c &&
+ git $cmd commit-C >expect &&
+ git $cmd --merge-base br2 >actual &&
+ test_cmp expect actual
+ '
+
+ test_expect_success "$cmd --merge-base with one commit and staged and unstaged changes" '
+ git checkout master &&
+ test_when_finished git reset --hard &&
+ echo staged >>c &&
+ git add c &&
+ echo unstaged >>c &&
+ git $cmd commit-C >expect &&
+ git $cmd --merge-base br2 >actual &&
+ test_cmp expect actual
+ '
+
+ test_expect_success "$cmd --merge-base --cached with one commit and staged and unstaged changes" '
+ git checkout master &&
+ test_when_finished git reset --hard &&
+ echo staged >>c &&
+ git add c &&
+ echo unstaged >>c &&
+ git $cmd --cached commit-C >expect &&
+ git $cmd --cached --merge-base br2 >actual &&
+ test_cmp expect actual
+ '
+
+ test_expect_success "$cmd --merge-base with non-commit" '
+ git checkout master &&
+ test_must_fail git $cmd --merge-base master^{tree} 2>err &&
+ test_i18ngrep "fatal: --merge-base only works with commits" err
+ '
+
+ test_expect_success "$cmd --merge-base with no merge bases and one commit" '
+ git checkout master &&
+ test_must_fail git $cmd --merge-base br3 2>err &&
+ test_i18ngrep "fatal: no merge base found" err
+ '
+
+ test_expect_success "$cmd --merge-base with multiple merge bases and one commit" '
+ git checkout master &&
+ test_must_fail git $cmd --merge-base br1 2>err &&
+ test_i18ngrep "fatal: multiple merge bases found" err
+ '
+done
+
test_done