2011-02-19 14:17:54 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2012-04-09 02:18:02 +02:00
|
|
|
test_description='git p4 tests'
|
2011-02-19 14:17:54 +01:00
|
|
|
|
2020-11-19 00:44:44 +01:00
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
tests: mark tests relying on the current default for `init.defaultBranch`
In addition to the manual adjustment to let the `linux-gcc` CI job run
the test suite with `master` and then with `main`, this patch makes sure
that GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set in all test scripts
that currently rely on the initial branch name being `master by default.
To determine which test scripts to mark up, the first step was to
force-set the default branch name to `master` in
- all test scripts that contain the keyword `master`,
- t4211, which expects `t/t4211/history.export` with a hard-coded ref to
initialize the default branch,
- t5560 because it sources `t/t556x_common` which uses `master`,
- t8002 and t8012 because both source `t/annotate-tests.sh` which also
uses `master`)
This trick was performed by this command:
$ sed -i '/^ *\. \.\/\(test-lib\|lib-\(bash\|cvs\|git-svn\)\|gitweb-lib\)\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' $(git grep -l master t/t[0-9]*.sh) \
t/t4211*.sh t/t5560*.sh t/t8002*.sh t/t8012*.sh
After that, careful, manual inspection revealed that some of the test
scripts containing the needle `master` do not actually rely on a
specific default branch name: either they mention `master` only in a
comment, or they initialize that branch specificially, or they do not
actually refer to the current default branch. Therefore, the
aforementioned modification was undone in those test scripts thusly:
$ git checkout HEAD -- \
t/t0027-auto-crlf.sh t/t0060-path-utils.sh \
t/t1011-read-tree-sparse-checkout.sh \
t/t1305-config-include.sh t/t1309-early-config.sh \
t/t1402-check-ref-format.sh t/t1450-fsck.sh \
t/t2024-checkout-dwim.sh \
t/t2106-update-index-assume-unchanged.sh \
t/t3040-subprojects-basic.sh t/t3301-notes.sh \
t/t3308-notes-merge.sh t/t3423-rebase-reword.sh \
t/t3436-rebase-more-options.sh \
t/t4015-diff-whitespace.sh t/t4257-am-interactive.sh \
t/t5323-pack-redundant.sh t/t5401-update-hooks.sh \
t/t5511-refspec.sh t/t5526-fetch-submodules.sh \
t/t5529-push-errors.sh t/t5530-upload-pack-error.sh \
t/t5548-push-porcelain.sh \
t/t5552-skipping-fetch-negotiator.sh \
t/t5572-pull-submodule.sh t/t5608-clone-2gb.sh \
t/t5614-clone-submodules-shallow.sh \
t/t7508-status.sh t/t7606-merge-custom.sh \
t/t9302-fast-import-unpack-limit.sh
We excluded one set of test scripts in these commands, though: the range
of `git p4` tests. The reason? `git p4` stores the (foreign) remote
branch in the branch called `p4/master`, which is obviously not the
default branch. Manual analysis revealed that only five of these tests
actually require a specific default branch name to pass; They were
modified thusly:
$ sed -i '/^ *\. \.\/lib-git-p4\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' t/t980[0167]*.sh t/t9811*.sh
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-11-19 00:44:19 +01:00
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
2011-08-23 04:20:33 +02:00
|
|
|
. ./lib-git-p4.sh
|
2011-02-19 14:17:54 +01:00
|
|
|
|
2011-08-23 04:20:33 +02:00
|
|
|
test_expect_success 'start p4d' '
|
|
|
|
start_p4d
|
2011-02-19 14:17:54 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'add p4 files' '
|
2011-08-23 04:20:33 +02:00
|
|
|
(
|
|
|
|
cd "$cli" &&
|
|
|
|
echo file1 >file1 &&
|
|
|
|
p4 add file1 &&
|
|
|
|
p4 submit -d "file1" &&
|
|
|
|
echo file2 >file2 &&
|
|
|
|
p4 add file2 &&
|
|
|
|
p4 submit -d "file2"
|
|
|
|
)
|
2011-02-19 14:17:54 +01:00
|
|
|
'
|
|
|
|
|
2012-04-09 02:18:02 +02:00
|
|
|
test_expect_success 'basic git p4 clone' '
|
|
|
|
git p4 clone --dest="$git" //depot &&
|
2011-07-31 15:44:50 +02:00
|
|
|
test_when_finished cleanup_git &&
|
2011-08-23 04:20:33 +02:00
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
git log --oneline >lines &&
|
|
|
|
test_line_count = 1 lines
|
|
|
|
)
|
2011-03-12 17:24:49 +01:00
|
|
|
'
|
|
|
|
|
2013-01-27 04:11:06 +01:00
|
|
|
test_expect_success 'depot typo error' '
|
|
|
|
test_must_fail git p4 clone --dest="$git" /depot 2>errs &&
|
|
|
|
grep "Depot paths must start with" errs
|
|
|
|
'
|
|
|
|
|
2012-04-09 02:18:02 +02:00
|
|
|
test_expect_success 'git p4 clone @all' '
|
|
|
|
git p4 clone --dest="$git" //depot@all &&
|
2011-07-31 15:44:50 +02:00
|
|
|
test_when_finished cleanup_git &&
|
2011-08-23 04:20:33 +02:00
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
git log --oneline >lines &&
|
|
|
|
test_line_count = 2 lines
|
|
|
|
)
|
2011-02-19 14:17:54 +01:00
|
|
|
'
|
|
|
|
|
2012-04-09 02:18:02 +02:00
|
|
|
test_expect_success 'git p4 sync uninitialized repo' '
|
2011-03-16 21:53:53 +01:00
|
|
|
test_create_repo "$git" &&
|
2011-07-31 15:44:50 +02:00
|
|
|
test_when_finished cleanup_git &&
|
2011-08-23 04:20:33 +02:00
|
|
|
(
|
|
|
|
cd "$git" &&
|
2012-06-27 14:00:59 +02:00
|
|
|
test_must_fail git p4 sync 2>errs &&
|
|
|
|
test_i18ngrep "Perhaps you never did" errs
|
2011-08-23 04:20:33 +02:00
|
|
|
)
|
2011-03-16 21:53:53 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
#
|
|
|
|
# Create a git repo by hand. Add a commit so that HEAD is valid.
|
|
|
|
# Test imports a new p4 repository into a new git branch.
|
|
|
|
#
|
2012-04-09 02:18:02 +02:00
|
|
|
test_expect_success 'git p4 sync new branch' '
|
2011-03-16 21:53:53 +01:00
|
|
|
test_create_repo "$git" &&
|
2011-07-31 15:44:50 +02:00
|
|
|
test_when_finished cleanup_git &&
|
2011-08-23 04:20:33 +02:00
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
test_commit head &&
|
2012-04-09 02:18:02 +02:00
|
|
|
git p4 sync --branch=refs/remotes/p4/depot //depot@all &&
|
2011-08-23 04:20:33 +02:00
|
|
|
git log --oneline p4/depot >lines &&
|
|
|
|
test_line_count = 2 lines
|
|
|
|
)
|
2011-03-16 21:53:53 +01:00
|
|
|
'
|
|
|
|
|
2011-12-25 03:07:33 +01:00
|
|
|
test_expect_success 'clone two dirs' '
|
|
|
|
(
|
|
|
|
cd "$cli" &&
|
|
|
|
mkdir sub1 sub2 &&
|
|
|
|
echo sub1/f1 >sub1/f1 &&
|
|
|
|
echo sub2/f2 >sub2/f2 &&
|
|
|
|
p4 add sub1/f1 &&
|
|
|
|
p4 submit -d "sub1/f1" &&
|
|
|
|
p4 add sub2/f2 &&
|
|
|
|
p4 submit -d "sub2/f2"
|
|
|
|
) &&
|
2012-04-09 02:18:02 +02:00
|
|
|
git p4 clone --dest="$git" //depot/sub1 //depot/sub2 &&
|
2011-12-25 03:07:33 +01:00
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
git ls-files >lines &&
|
|
|
|
test_line_count = 2 lines &&
|
|
|
|
git log --oneline p4/master >lines &&
|
|
|
|
test_line_count = 1 lines
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'clone two dirs, @all' '
|
|
|
|
(
|
|
|
|
cd "$cli" &&
|
|
|
|
echo sub1/f3 >sub1/f3 &&
|
|
|
|
p4 add sub1/f3 &&
|
|
|
|
p4 submit -d "sub1/f3"
|
|
|
|
) &&
|
2012-04-09 02:18:02 +02:00
|
|
|
git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all &&
|
2011-12-25 03:07:33 +01:00
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
git ls-files >lines &&
|
|
|
|
test_line_count = 3 lines &&
|
|
|
|
git log --oneline p4/master >lines &&
|
|
|
|
test_line_count = 3 lines
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'clone two dirs, @all, conflicting files' '
|
|
|
|
(
|
|
|
|
cd "$cli" &&
|
|
|
|
echo sub2/f3 >sub2/f3 &&
|
|
|
|
p4 add sub2/f3 &&
|
|
|
|
p4 submit -d "sub2/f3"
|
|
|
|
) &&
|
2012-04-09 02:18:02 +02:00
|
|
|
git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all &&
|
2011-12-25 03:07:33 +01:00
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
git ls-files >lines &&
|
|
|
|
test_line_count = 3 lines &&
|
|
|
|
git log --oneline p4/master >lines &&
|
|
|
|
test_line_count = 4 lines &&
|
|
|
|
echo sub2/f3 >expected &&
|
|
|
|
test_cmp expected f3
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2016-12-17 23:11:23 +01:00
|
|
|
test_expect_success 'clone two dirs, each edited by submit, single git commit' '
|
|
|
|
(
|
|
|
|
cd "$cli" &&
|
|
|
|
echo sub1/f4 >sub1/f4 &&
|
|
|
|
p4 add sub1/f4 &&
|
|
|
|
echo sub2/f4 >sub2/f4 &&
|
|
|
|
p4 add sub2/f4 &&
|
|
|
|
p4 submit -d "sub1/f4 and sub2/f4"
|
|
|
|
) &&
|
|
|
|
git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all &&
|
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
git ls-files >lines &&
|
|
|
|
test_line_count = 4 lines &&
|
|
|
|
git log --oneline p4/master >lines &&
|
|
|
|
test_line_count = 5 lines
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-06-10 09:30:58 +02:00
|
|
|
revision_ranges="2000/01/01,#head \
|
|
|
|
1,2080/01/01 \
|
|
|
|
2000/01/01,2080/01/01 \
|
|
|
|
2000/01/01,1000 \
|
|
|
|
1,1000"
|
|
|
|
|
|
|
|
test_expect_success 'clone using non-numeric revision ranges' '
|
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
for r in $revision_ranges
|
|
|
|
do
|
|
|
|
rm -fr "$git" &&
|
|
|
|
test ! -d "$git" &&
|
|
|
|
git p4 clone --dest="$git" //depot@$r &&
|
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
git ls-files >lines &&
|
2016-12-17 23:11:23 +01:00
|
|
|
test_line_count = 8 lines
|
2015-06-10 09:30:58 +02:00
|
|
|
)
|
|
|
|
done
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'clone with date range, excluding some changes' '
|
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
before=$(date +%Y/%m/%d:%H:%M:%S) &&
|
|
|
|
sleep 2 &&
|
|
|
|
(
|
|
|
|
cd "$cli" &&
|
|
|
|
:>date_range_test &&
|
|
|
|
p4 add date_range_test &&
|
|
|
|
p4 submit -d "Adding file"
|
|
|
|
) &&
|
|
|
|
git p4 clone --dest="$git" //depot@1,$before &&
|
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
test_path_is_missing date_range_test
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2011-02-19 14:17:55 +01:00
|
|
|
test_expect_success 'exit when p4 fails to produce marshaled output' '
|
2012-06-27 14:00:56 +02:00
|
|
|
mkdir badp4dir &&
|
|
|
|
test_when_finished "rm badp4dir/p4 && rmdir badp4dir" &&
|
|
|
|
cat >badp4dir/p4 <<-EOF &&
|
2011-02-19 14:17:55 +01:00
|
|
|
#!$SHELL_PATH
|
|
|
|
exit 1
|
|
|
|
EOF
|
2012-06-27 14:00:56 +02:00
|
|
|
chmod 755 badp4dir/p4 &&
|
2012-06-27 14:01:03 +02:00
|
|
|
(
|
|
|
|
PATH="$TRASH_DIRECTORY/badp4dir:$PATH" &&
|
|
|
|
export PATH &&
|
|
|
|
test_expect_code 1 git p4 clone --dest="$git" //depot >errs 2>&1
|
|
|
|
) &&
|
2014-08-13 21:30:11 +02:00
|
|
|
test_i18ngrep ! Traceback errs
|
2011-02-19 14:17:55 +01:00
|
|
|
'
|
|
|
|
|
2012-11-23 23:35:36 +01:00
|
|
|
# Hide a file from p4d, make sure we catch its complaint. This won't fail in
|
|
|
|
# p4 changes, files, or describe; just in p4 print. If P4CLIENT is unset, the
|
|
|
|
# message will include "Librarian checkout".
|
|
|
|
test_expect_success 'exit gracefully for p4 server errors' '
|
|
|
|
test_when_finished "mv \"$db\"/depot/file1,v,hidden \"$db\"/depot/file1,v" &&
|
|
|
|
mv "$db"/depot/file1,v "$db"/depot/file1,v,hidden &&
|
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
test_expect_code 1 git p4 clone --dest="$git" //depot@1 >out 2>err &&
|
|
|
|
test_i18ngrep "Error from p4 print" err
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'clone --bare should make a bare repository' '
|
2012-06-27 14:01:01 +02:00
|
|
|
rm -rf "$git" &&
|
2012-04-09 02:18:02 +02:00
|
|
|
git p4 clone --dest="$git" --bare //depot &&
|
2011-07-31 15:44:50 +02:00
|
|
|
test_when_finished cleanup_git &&
|
2011-08-23 04:20:33 +02:00
|
|
|
(
|
|
|
|
cd "$git" &&
|
2013-01-15 01:47:00 +01:00
|
|
|
test_path_is_missing .git &&
|
|
|
|
git config --get --bool core.bare true &&
|
|
|
|
git rev-parse --verify refs/remotes/p4/master &&
|
|
|
|
git rev-parse --verify refs/remotes/p4/HEAD &&
|
2020-11-19 00:44:44 +01:00
|
|
|
git rev-parse --verify refs/heads/main &&
|
2013-01-15 01:47:00 +01:00
|
|
|
git rev-parse --verify HEAD
|
2011-08-23 04:20:33 +02:00
|
|
|
)
|
2011-02-19 14:18:01 +01:00
|
|
|
'
|
|
|
|
|
2011-07-31 15:45:55 +02:00
|
|
|
# Sleep a bit so that the top-most p4 change did not happen "now". Then
|
|
|
|
# import the repo and make sure that the initial import has the same time
|
|
|
|
# as the top-most change.
|
|
|
|
test_expect_success 'initial import time from top change time' '
|
|
|
|
p4change=$(p4 -G changes -m 1 //depot/... | marshal_dump change) &&
|
|
|
|
p4time=$(p4 -G changes -m 1 //depot/... | marshal_dump time) &&
|
|
|
|
sleep 3 &&
|
2012-04-09 02:18:02 +02:00
|
|
|
git p4 clone --dest="$git" //depot &&
|
2011-07-31 15:45:55 +02:00
|
|
|
test_when_finished cleanup_git &&
|
2011-08-23 04:20:33 +02:00
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
gittime=$(git show -s --raw --pretty=format:%at HEAD) &&
|
|
|
|
echo $p4time $gittime &&
|
|
|
|
test $p4time = $gittime
|
|
|
|
)
|
2011-07-31 15:45:55 +02:00
|
|
|
'
|
2011-05-13 21:46:00 +02:00
|
|
|
|
2012-11-23 23:35:37 +01:00
|
|
|
test_expect_success 'unresolvable host in P4PORT should display error' '
|
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
git p4 clone --dest="$git" //depot &&
|
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
P4PORT=nosuchhost:65537 &&
|
|
|
|
export P4PORT &&
|
|
|
|
test_expect_code 1 git p4 sync >out 2>err &&
|
|
|
|
grep "connect to nosuchhost" err
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2018-07-27 13:22:22 +02:00
|
|
|
# Test following scenarios:
|
|
|
|
# - Without ".git/hooks/p4-pre-submit" , submit should continue
|
|
|
|
# - With the hook returning 0, submit should continue
|
|
|
|
# - With the hook returning 1, submit should abort
|
|
|
|
test_expect_success 'run hook p4-pre-submit before submit' '
|
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
git p4 clone --dest="$git" //depot &&
|
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
echo "hello world" >hello.txt &&
|
|
|
|
git add hello.txt &&
|
|
|
|
git commit -m "add hello.txt" &&
|
|
|
|
git config git-p4.skipSubmitEdit true &&
|
|
|
|
git p4 submit --dry-run >out &&
|
|
|
|
grep "Would apply" out &&
|
|
|
|
mkdir -p .git/hooks &&
|
|
|
|
write_script .git/hooks/p4-pre-submit <<-\EOF &&
|
|
|
|
exit 0
|
|
|
|
EOF
|
|
|
|
git p4 submit --dry-run >out &&
|
|
|
|
grep "Would apply" out &&
|
|
|
|
write_script .git/hooks/p4-pre-submit <<-\EOF &&
|
|
|
|
exit 1
|
|
|
|
EOF
|
|
|
|
test_must_fail git p4 submit --dry-run >errs 2>&1 &&
|
|
|
|
! grep "Would apply" errs
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-11-21 10:54:41 +01:00
|
|
|
test_expect_success 'submit from detached head' '
|
2015-11-21 10:54:39 +01:00
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
git p4 clone --dest="$git" //depot &&
|
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
git checkout p4/master &&
|
|
|
|
>detached_head_test &&
|
|
|
|
git add detached_head_test &&
|
|
|
|
git commit -m "add detached_head" &&
|
|
|
|
git config git-p4.skipSubmitEdit true &&
|
|
|
|
git p4 submit &&
|
|
|
|
git p4 rebase &&
|
|
|
|
git log p4/master | grep detached_head
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2016-12-13 22:51:28 +01:00
|
|
|
test_expect_success 'submit from worktree' '
|
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
git p4 clone --dest="$git" //depot &&
|
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
git worktree add ../worktree-test
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd "$git/../worktree-test" &&
|
|
|
|
test_commit "worktree-commit" &&
|
|
|
|
git config git-p4.skipSubmitEdit true &&
|
|
|
|
git p4 submit
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd "$cli" &&
|
|
|
|
p4 sync &&
|
|
|
|
test_path_is_file worktree-commit.t
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2011-02-19 14:17:54 +01:00
|
|
|
test_done
|