diff options
Diffstat (limited to 't')
-rwxr-xr-x | t/t0201-gettext-fallbacks.sh | 51 | ||||
-rwxr-xr-x | t/t1011-read-tree-sparse-checkout.sh | 53 | ||||
-rwxr-xr-x | t/t3503-cherry-pick-root.sh | 27 | ||||
-rwxr-xr-x | t/t3703-add-magic-pathspec.sh | 58 | ||||
-rwxr-xr-x | t/t4208-log-magic-pathspec.sh | 36 | ||||
-rwxr-xr-x | t/t5532-fetch-proxy.sh | 43 | ||||
-rwxr-xr-x | t/t6017-rev-list-stdin.sh | 17 | ||||
-rwxr-xr-x | t/t6022-merge-rename.sh | 63 | ||||
-rwxr-xr-x | t/t6050-replace.sh | 18 | ||||
-rwxr-xr-x | t/t7506-status-submodule.sh | 92 | ||||
-rwxr-xr-x | t/t8008-blame-formats.sh | 90 | ||||
-rwxr-xr-x | t/t9116-git-svn-log.sh | 15 | ||||
-rwxr-xr-x | t/t9800-git-p4.sh | 125 |
13 files changed, 613 insertions, 75 deletions
diff --git a/t/t0201-gettext-fallbacks.sh b/t/t0201-gettext-fallbacks.sh new file mode 100755 index 0000000000..54d98b9b10 --- /dev/null +++ b/t/t0201-gettext-fallbacks.sh @@ -0,0 +1,51 @@ +#!/bin/sh +# +# Copyright (c) 2010 Ævar Arnfjörð Bjarmason +# + +test_description='Gettext Shell fallbacks' + +. ./test-lib.sh +. "$GIT_BUILD_DIR"/git-sh-i18n + +test_expect_success 'gettext: our gettext() fallback has pass-through semantics' ' + printf "test" >expect && + gettext "test" >actual && + test_i18ncmp expect actual && + printf "test more words" >expect && + gettext "test more words" >actual && + test_i18ncmp expect actual +' + +test_expect_success 'eval_gettext: our eval_gettext() fallback has pass-through semantics' ' + printf "test" >expect && + eval_gettext "test" >actual && + test_i18ncmp expect actual && + printf "test more words" >expect && + eval_gettext "test more words" >actual && + test_i18ncmp expect actual +' + +test_expect_success 'eval_gettext: our eval_gettext() fallback can interpolate variables' ' + printf "test YesPlease" >expect && + GIT_INTERNAL_GETTEXT_TEST_FALLBACKS=YesPlease eval_gettext "test \$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" >actual && + test_i18ncmp expect actual +' + +test_expect_success 'eval_gettext: our eval_gettext() fallback can interpolate variables with spaces' ' + cmdline="git am" && + export cmdline; + printf "When you have resolved this problem run git am --resolved." >expect && + eval_gettext "When you have resolved this problem run \$cmdline --resolved." >actual + test_i18ncmp expect actual +' + +test_expect_success 'eval_gettext: our eval_gettext() fallback can interpolate variables with spaces and quotes' ' + cmdline="git am" && + export cmdline; + printf "When you have resolved this problem run \"git am --resolved\"." >expect && + eval_gettext "When you have resolved this problem run \"\$cmdline --resolved\"." >actual + test_i18ncmp expect actual +' + +test_done diff --git a/t/t1011-read-tree-sparse-checkout.sh b/t/t1011-read-tree-sparse-checkout.sh index de84e35c43..20a50eba5b 100755 --- a/t/t1011-read-tree-sparse-checkout.sh +++ b/t/t1011-read-tree-sparse-checkout.sh @@ -17,19 +17,21 @@ test_expect_success 'setup' ' cat >expected <<-\EOF && 100644 77f0ba1734ed79d12881f81b36ee134de6a3327b 0 init.t 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 sub/added + 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 sub/addedtoo 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 subsub/added EOF cat >expected.swt <<-\EOF && H init.t H sub/added + H sub/addedtoo H subsub/added EOF test_commit init && echo modified >>init.t && mkdir sub subsub && - touch sub/added subsub/added && - git add init.t sub/added subsub/added && + touch sub/added sub/addedtoo subsub/added && + git add init.t sub/added sub/addedtoo subsub/added && git commit -m "modified and added" && git tag top && git rm sub/added && @@ -83,6 +85,7 @@ test_expect_success 'match directories with trailing slash' ' cat >expected.swt-noinit <<-\EOF && S init.t H sub/added + H sub/addedtoo S subsub/added EOF @@ -95,7 +98,7 @@ test_expect_success 'match directories with trailing slash' ' ' test_expect_success 'match directories without trailing slash' ' - echo sub >>.git/info/sparse-checkout && + echo sub >.git/info/sparse-checkout && git read-tree -m -u HEAD && git ls-files -t >result && test_cmp expected.swt-noinit result && @@ -103,8 +106,49 @@ test_expect_success 'match directories without trailing slash' ' test -f sub/added ' +test_expect_success 'match directories with negated patterns' ' + cat >expected.swt-negation <<\EOF && +S init.t +S sub/added +H sub/addedtoo +S subsub/added +EOF + + cat >.git/info/sparse-checkout <<\EOF && +sub +!sub/added +EOF + git read-tree -m -u HEAD && + git ls-files -t >result && + test_cmp expected.swt-negation result && + test ! -f init.t && + test ! -f sub/added && + test -f sub/addedtoo +' + +test_expect_success 'match directories with negated patterns (2)' ' + cat >expected.swt-negation2 <<\EOF && +H init.t +H sub/added +S sub/addedtoo +H subsub/added +EOF + + cat >.git/info/sparse-checkout <<\EOF && +/* +!sub +sub/added +EOF + git read-tree -m -u HEAD && + git ls-files -t >result && + test_cmp expected.swt-negation2 result && + test -f init.t && + test -f sub/added && + test ! -f sub/addedtoo +' + test_expect_success 'match directory pattern' ' - echo "s?b" >>.git/info/sparse-checkout && + echo "s?b" >.git/info/sparse-checkout && git read-tree -m -u HEAD && git ls-files -t >result && test_cmp expected.swt-noinit result && @@ -116,6 +160,7 @@ test_expect_success 'checkout area changes' ' cat >expected.swt-nosub <<-\EOF && H init.t S sub/added + S sub/addedtoo S subsub/added EOF diff --git a/t/t3503-cherry-pick-root.sh b/t/t3503-cherry-pick-root.sh index b0faa29918..9aefe3a1be 100755 --- a/t/t3503-cherry-pick-root.sh +++ b/t/t3503-cherry-pick-root.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='test cherry-picking a root commit' +test_description='test cherry-picking (and reverting) a root commit' . ./test-lib.sh @@ -23,7 +23,30 @@ test_expect_success setup ' test_expect_success 'cherry-pick a root commit' ' git cherry-pick master && - test first = $(cat file1) + echo first >expect && + test_cmp expect file1 + +' + +test_expect_success 'revert a root commit' ' + + git revert master && + test_path_is_missing file1 + +' + +test_expect_success 'cherry-pick a root commit with an external strategy' ' + + git cherry-pick --strategy=resolve master && + echo first >expect && + test_cmp expect file1 + +' + +test_expect_success 'revert a root commit with an external strategy' ' + + git revert --strategy=resolve master && + test_path_is_missing file1 ' diff --git a/t/t3703-add-magic-pathspec.sh b/t/t3703-add-magic-pathspec.sh new file mode 100755 index 0000000000..e508246c0c --- /dev/null +++ b/t/t3703-add-magic-pathspec.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +test_description='magic pathspec tests using git-add' + +. ./test-lib.sh + +test_expect_success 'setup' ' + mkdir sub anothersub && + : >sub/foo && + : >anothersub/foo +' + +test_expect_success 'add :/' " + cat >expected <<-EOF && + add 'anothersub/foo' + add 'expected' + add 'sub/actual' + add 'sub/foo' + EOF + (cd sub && git add -n :/ >actual) && + test_cmp expected sub/actual +" + +cat >expected <<EOF +add 'anothersub/foo' +EOF + +test_expect_success 'add :/anothersub' ' + (cd sub && git add -n :/anothersub >actual) && + test_cmp expected sub/actual +' + +test_expect_success 'add :/non-existent' ' + (cd sub && test_must_fail git add -n :/non-existent) +' + +cat >expected <<EOF +add 'sub/foo' +EOF + +test_expect_success 'a file with the same (long) magic name exists' ' + : >":(icase)ha" && + test_must_fail git add -n ":(icase)ha" && + git add -n "./:(icase)ha" +' + +if mkdir ":" 2>/dev/null +then + test_set_prereq COLON_DIR +fi + +test_expect_success COLON_DIR 'a file with the same (short) magic name exists' ' + : >":/bar" && + test_must_fail git add -n :/bar && + git add -n "./:/bar" +' + +test_done diff --git a/t/t4208-log-magic-pathspec.sh b/t/t4208-log-magic-pathspec.sh new file mode 100755 index 0000000000..2c482b622b --- /dev/null +++ b/t/t4208-log-magic-pathspec.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +test_description='magic pathspec tests using git-log' + +. ./test-lib.sh + +test_expect_success 'setup' ' + test_commit initial && + test_tick && + git commit --allow-empty -m empty && + mkdir sub +' + +test_expect_success '"git log :/" should be ambiguous' ' + test_must_fail git log :/ 2>error && + grep ambiguous error +' + +test_expect_success '"git log :" should be ambiguous' ' + test_must_fail git log : 2>error && + grep ambiguous error +' + +test_expect_success 'git log -- :' ' + git log -- : +' + +test_expect_success 'git log HEAD -- :/' ' + cat >expected <<-EOF && + 24b24cf initial + EOF + (cd sub && git log --oneline HEAD -- :/ >../actual) && + test_cmp expected actual +' + +test_done diff --git a/t/t5532-fetch-proxy.sh b/t/t5532-fetch-proxy.sh new file mode 100755 index 0000000000..62f2460047 --- /dev/null +++ b/t/t5532-fetch-proxy.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +test_description='fetching via git:// using core.gitproxy' +. ./test-lib.sh + +test_expect_success 'setup remote repo' ' + git init remote && + (cd remote && + echo content >file && + git add file && + git commit -m one + ) +' + +cat >proxy <<'EOF' +#!/bin/sh +echo >&2 "proxying for $*" +cmd=`perl -e ' + read(STDIN, $buf, 4); + my $n = hex($buf) - 4; + read(STDIN, $buf, $n); + my ($cmd, $other) = split /\0/, $buf; + # drop absolute-path on repo name + $cmd =~ s{ /}{ }; + print $cmd; +'` +echo >&2 "Running '$cmd'" +exec $cmd +EOF +chmod +x proxy +test_expect_success 'setup local repo' ' + git remote add fake git://example.com/remote && + git config core.gitproxy ./proxy +' + +test_expect_success 'fetch through proxy works' ' + git fetch fake && + echo one >expect && + git log -1 --format=%s FETCH_HEAD >actual && + test_cmp expect actual +' + +test_done diff --git a/t/t6017-rev-list-stdin.sh b/t/t6017-rev-list-stdin.sh index f1c32dba42..667b37564e 100755 --- a/t/t6017-rev-list-stdin.sh +++ b/t/t6017-rev-list-stdin.sh @@ -58,4 +58,21 @@ check side-3 ^side-4 -- file-3 check side-3 ^side-2 check side-3 ^side-2 -- file-1 +test_expect_success 'not only --stdin' ' + cat >expect <<-EOF && + 7 + + file-1 + file-2 + EOF + cat >input <<-EOF && + ^master^ + -- + file-2 + EOF + git log --pretty=tformat:%s --name-only --stdin master -- file-1 \ + <input >actual && + test_cmp expect actual +' + test_done diff --git a/t/t6022-merge-rename.sh b/t/t6022-merge-rename.sh index 5f3b604fd9..1ed259d864 100755 --- a/t/t6022-merge-rename.sh +++ b/t/t6022-merge-rename.sh @@ -609,67 +609,4 @@ test_expect_success 'check handling of differently renamed file with D/F conflic ! test -f original ' -test_expect_success 'setup avoid unnecessary update, normal rename' ' - git reset --hard && - git checkout --orphan avoid-unnecessary-update-1 && - git rm -rf . && - git clean -fdqx && - - printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original && - git add -A && - git commit -m "Common commmit" && - - git mv original rename && - echo 11 >>rename && - git add -u && - git commit -m "Renamed and modified" && - - git checkout -b merge-branch-1 HEAD~1 && - echo "random content" >random-file && - git add -A && - git commit -m "Random, unrelated changes" -' - -test_expect_success 'avoid unnecessary update, normal rename' ' - git checkout -q avoid-unnecessary-update-1^0 && - test-chmtime =1000000000 rename && - test-chmtime -v +0 rename >expect && - git merge merge-branch-1 && - test-chmtime -v +0 rename >actual && - test_cmp expect actual # "rename" should have stayed intact -' - -test_expect_success 'setup to test avoiding unnecessary update, with D/F conflict' ' - git reset --hard && - git checkout --orphan avoid-unnecessary-update-2 && - git rm -rf . && - git clean -fdqx && - - mkdir df && - printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file && - git add -A && - git commit -m "Common commmit" && - - git mv df/file temp && - rm -rf df && - git mv temp df && - echo 11 >>df && - git add -u && - git commit -m "Renamed and modified" && - - git checkout -b merge-branch-2 HEAD~1 && - >unrelated-change && - git add unrelated-change && - git commit -m "Only unrelated changes" -' - -test_expect_failure 'avoid unnecessary update, with D/F conflict' ' - git checkout -q avoid-unnecessary-update-2^0 && - test-chmtime =1000000000 df && - test-chmtime -v +0 df >expect && - git merge merge-branch-2 && - test-chmtime -v +0 df >actual && - test_cmp expect actual # "df" should have stayed intact -' - test_done diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index ae2194e07d..5c87f28e4e 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -236,6 +236,20 @@ test_expect_success 'index-pack and replacements' ' git index-pack test-*.pack ' -# -# +test_expect_success 'not just commits' ' + echo replaced >file && + git add file && + REPLACED=$(git rev-parse :file) && + mv file file.replaced && + + echo original >file && + git add file && + ORIGINAL=$(git rev-parse :file) && + git update-ref refs/replace/$ORIGINAL $REPLACED && + mv file file.original && + + git checkout file && + test_cmp file.replaced file +' + test_done diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh index c8d50a6567..d31b34da83 100755 --- a/t/t7506-status-submodule.sh +++ b/t/t7506-status-submodule.sh @@ -4,17 +4,21 @@ test_description='git status for submodule' . ./test-lib.sh -test_expect_success 'setup' ' - test_create_repo sub && +test_create_repo_with_commit () { + test_create_repo "$1" && ( - cd sub && + cd "$1" && : >bar && git add bar && git commit -m " Add bar" && : >foo && git add foo && git commit -m " Add foo" - ) && + ) +} + +test_expect_success 'setup' ' + test_create_repo_with_commit sub && echo output > .gitignore && git add sub .gitignore && git commit -m "Add submodule sub" @@ -187,4 +191,84 @@ test_expect_success 'status -a clean (empty submodule dir)' ' test_i18ngrep "nothing to commit" output ' +cat >status_expect <<\EOF +AA .gitmodules +A sub1 +EOF + +test_expect_success 'status with merge conflict in .gitmodules' ' + git clone . super && + test_create_repo_with_commit sub1 && + test_tick && + test_create_repo_with_commit sub2 && + ( + cd super && + prev=$(git rev-parse HEAD) && + git checkout -b add_sub1 && + git submodule add ../sub1 && + git commit -m "add sub1" && + git checkout -b add_sub2 $prev && + git submodule add ../sub2 && + git commit -m "add sub2" && + git checkout -b merge_conflict_gitmodules && + test_must_fail git merge add_sub1 && + git status -s >../status_actual 2>&1 + ) && + test_cmp status_actual status_expect +' + +sha1_merge_sub1=$(cd sub1 && git rev-parse HEAD) +sha1_merge_sub2=$(cd sub2 && git rev-parse HEAD) +short_sha1_merge_sub1=$(cd sub1 && git rev-parse --short HEAD) +short_sha1_merge_sub2=$(cd sub2 && git rev-parse --short HEAD) +cat >diff_expect <<\EOF +diff --cc .gitmodules +index badaa4c,44f999a..0000000 +--- a/.gitmodules ++++ b/.gitmodules +@@@ -1,3 -1,3 +1,9 @@@ +++<<<<<<< HEAD + +[submodule "sub2"] + + path = sub2 + + url = ../sub2 +++======= ++ [submodule "sub1"] ++ path = sub1 ++ url = ../sub1 +++>>>>>>> add_sub1 +EOF + +cat >diff_submodule_expect <<\EOF +diff --cc .gitmodules +index badaa4c,44f999a..0000000 +--- a/.gitmodules ++++ b/.gitmodules +@@@ -1,3 -1,3 +1,9 @@@ +++<<<<<<< HEAD + +[submodule "sub2"] + + path = sub2 + + url = ../sub2 +++======= ++ [submodule "sub1"] ++ path = sub1 ++ url = ../sub1 +++>>>>>>> add_sub1 +EOF + +test_expect_success 'diff with merge conflict in .gitmodules' ' + ( + cd super && + git diff >../diff_actual 2>&1 + ) && + test_cmp diff_actual diff_expect +' + +test_expect_success 'diff --submodule with merge conflict in .gitmodules' ' + ( + cd super && + git diff --submodule >../diff_submodule_actual 2>&1 + ) && + test_cmp diff_submodule_actual diff_submodule_expect +' + test_done diff --git a/t/t8008-blame-formats.sh b/t/t8008-blame-formats.sh new file mode 100755 index 0000000000..d15f8b3d47 --- /dev/null +++ b/t/t8008-blame-formats.sh @@ -0,0 +1,90 @@ +#!/bin/sh + +test_description='blame output in various formats on a simple case' +. ./test-lib.sh + +test_expect_success 'setup' ' + echo a >file && + git add file + test_tick && + git commit -m one && + echo b >>file && + echo c >>file && + echo d >>file && + test_tick && + git commit -a -m two +' + +cat >expect <<'EOF' +^baf5e0b (A U Thor 2005-04-07 15:13:13 -0700 1) a +8825379d (A U Thor 2005-04-07 15:14:13 -0700 2) b +8825379d (A U Thor 2005-04-07 15:14:13 -0700 3) c +8825379d (A U Thor 2005-04-07 15:14:13 -0700 4) d +EOF +test_expect_success 'normal blame output' ' + git blame file >actual && + test_cmp expect actual +' + +ID1=baf5e0b3869e0b2b2beb395a3720c7b51eac94fc +COMMIT1='author A U Thor +author-mail <author@example.com> +author-time 1112911993 +author-tz -0700 +committer C O Mitter +committer-mail <committer@example.com> +committer-time 1112911993 +committer-tz -0700 +summary one +boundary +filename file' +ID2=8825379dfb8a1267b58e8e5bcf69eec838f685ec +COMMIT2='author A U Thor +author-mail <author@example.com> +author-time 1112912053 +author-tz -0700 +committer C O Mitter +committer-mail <committer@example.com> +committer-time 1112912053 +committer-tz -0700 +summary two +previous baf5e0b3869e0b2b2beb395a3720c7b51eac94fc file +filename file' + +cat >expect <<EOF +$ID1 1 1 1 +$COMMIT1 + a +$ID2 2 2 3 +$COMMIT2 + b +$ID2 3 3 + c +$ID2 4 4 + d +EOF +test_expect_success 'blame --porcelain output' ' + git blame --porcelain file >actual && + test_cmp expect actual +' + +cat >expect <<EOF +$ID1 1 1 1 +$COMMIT1 + a +$ID2 2 2 3 +$COMMIT2 + b +$ID2 3 3 +$COMMIT2 + c +$ID2 4 4 +$COMMIT2 + d +EOF +test_expect_success 'blame --line-porcelain output' ' + git blame --line-porcelain file >actual && + test_cmp expect actual +' + +test_done diff --git a/t/t9116-git-svn-log.sh b/t/t9116-git-svn-log.sh index 5d477e4bda..cf4c05261b 100755 --- a/t/t9116-git-svn-log.sh +++ b/t/t9116-git-svn-log.sh @@ -60,6 +60,21 @@ test_expect_success 'test ascending revision range' " git svn log -r 1:4 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r1-r2-r4 - " +test_expect_success 'test ascending revision range with --show-commit' " + git reset --hard trunk && + git svn log --show-commit -r 1:4 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r1-r2-r4 - + " + +test_expect_success 'test ascending revision range with --show-commit (sha1)' " + git svn find-rev r1 >expected-range-r1-r2-r4-sha1 && + git svn find-rev r2 >>expected-range-r1-r2-r4-sha1 && + git svn find-rev r4 >>expected-range-r1-r2-r4-sha1 && + git reset --hard trunk && + git svn log --show-commit -r 1:4 | grep '^r[0-9]' | cut -d'|' -f2 >out && + git rev-parse \$(cat out) >actual && + test_cmp expected-range-r1-r2-r4-sha1 actual + " + printf 'r4 \nr2 \nr1 \n' > expected-range-r4-r2-r1 test_expect_success 'test descending revision range' " diff --git a/t/t9800-git-p4.sh b/t/t9800-git-p4.sh index a523473954..33b0127651 100755 --- a/t/t9800-git-p4.sh +++ b/t/t9800-git-p4.sh @@ -12,6 +12,8 @@ test_description='git-p4 tests' GITP4=$GIT_BUILD_DIR/contrib/fast-import/git-p4 P4DPORT=10669 +export P4PORT=localhost:$P4DPORT + db="$TRASH_DIRECTORY/db" cli="$TRASH_DIRECTORY/cli" git="$TRASH_DIRECTORY/git" @@ -129,6 +131,129 @@ test_expect_success 'clone bare' ' rm -rf "$git" && mkdir "$git" ' +p4_add_user() { + name=$1 + fullname=$2 + p4 user -f -i <<EOF && +User: $name +Email: $name@localhost +FullName: $fullname +EOF + p4 passwd -P secret $name +} + +p4_grant_admin() { + name=$1 + p4 protect -o |\ + awk "{print}END{print \" admin user $name * //depot/...\"}" |\ + p4 protect -i +} + +p4_check_commit_author() { + file=$1 + user=$2 + if p4 changes -m 1 //depot/$file | grep $user > /dev/null ; then + return 0 + else + echo "file $file not modified by user $user" 1>&2 + return 1 + fi +} + +make_change_by_user() { + file=$1 name=$2 email=$3 && + echo "username: a change by $name" >>"$file" && + git add "$file" && + git commit --author "$name <$email>" -m "a change by $name" +} + +# Test username support, submitting as user 'alice' +test_expect_success 'preserve users' ' + p4_add_user alice Alice && + p4_add_user bob Bob && + p4_grant_admin alice && + "$GITP4" clone --dest="$git" //depot && + cd "$git" && + echo "username: a change by alice" >> file1 && + echo "username: a change by bob" >> file2 && + git commit --author "Alice <alice@localhost>" -m "a change by alice" file1 && + git commit --author "Bob <bob@localhost>" -m "a change by bob" file2 && + git config git-p4.skipSubmitEditCheck true && + P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit --preserve-user && + p4_check_commit_author file1 alice && + p4_check_commit_author file2 bob && + cd "$TRASH_DIRECTORY" && + rm -rf "$git" && mkdir "$git" +' + +# Test username support, submitting as bob, who lacks admin rights. Should +# not submit change to p4 (git diff should show deltas). +test_expect_success 'refuse to preserve users without perms' ' + "$GITP4" clone --dest="$git" //depot && + cd "$git" && + echo "username-noperms: a change by alice" >> file1 && + git commit --author "Alice <alice@localhost>" -m "perms: a change by alice" file1 && + ! P4EDITOR=touch P4USER=bob P4PASSWD=secret "$GITP4" commit --preserve-user && + ! git diff --exit-code HEAD..p4/master > /dev/null && + cd "$TRASH_DIRECTORY" && + rm -rf "$git" && mkdir "$git" +' + +# What happens with unknown author? Without allowMissingP4Users it should fail. +test_expect_success 'preserve user where author is unknown to p4' ' + "$GITP4" clone --dest="$git" //depot && + cd "$git" && + git config git-p4.skipSubmitEditCheck true + echo "username-bob: a change by bob" >> file1 && + git commit --author "Bob <bob@localhost>" -m "preserve: a change by bob" file1 && + echo "username-unknown: a change by charlie" >> file1 && + git commit --author "Charlie <charlie@localhost>" -m "preserve: a change by charlie" file1 && + ! P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit --preserve-user && + ! git diff --exit-code HEAD..p4/master > /dev/null && + echo "$0: repeat with allowMissingP4Users enabled" && + git config git-p4.allowMissingP4Users true && + git config git-p4.preserveUser true && + P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit && + git diff --exit-code HEAD..p4/master > /dev/null && + p4_check_commit_author file1 alice && + cd "$TRASH_DIRECTORY" && + rm -rf "$git" && mkdir "$git" +' + +# If we're *not* using --preserve-user, git-p4 should warn if we're submitting +# changes that are not all ours. +# Test: user in p4 and user unknown to p4. +# Test: warning disabled and user is the same. +test_expect_success 'not preserving user with mixed authorship' ' + "$GITP4" clone --dest="$git" //depot && + ( + cd "$git" && + git config git-p4.skipSubmitEditCheck true && + p4_add_user derek Derek && + + make_change_by_user usernamefile3 Derek derek@localhost && + P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && + grep "git author derek@localhost does not match" actual && + + make_change_by_user usernamefile3 Charlie charlie@localhost && + P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && + grep "git author charlie@localhost does not match" actual && + + make_change_by_user usernamefile3 alice alice@localhost && + P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && + ! grep "git author.*does not match" actual && + + git config git-p4.skipUserNameCheck true && + make_change_by_user usernamefile3 Charlie charlie@localhost && + P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && + ! grep "git author.*does not match" actual && + + p4_check_commit_author usernamefile3 alice + ) && + rm -rf "$git" && mkdir "$git" +' + + test_expect_success 'shutdown' ' pid=`pgrep -f p4d` && test -n "$pid" && |