2012-04-11 17:21:24 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='git p4 label tests'
|
|
|
|
|
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
|
|
|
|
|
2012-04-11 17:21:24 +02:00
|
|
|
. ./lib-git-p4.sh
|
|
|
|
|
|
|
|
test_expect_success 'start p4d' '
|
|
|
|
start_p4d
|
|
|
|
'
|
|
|
|
|
|
|
|
# Basic p4 label import tests.
|
|
|
|
#
|
|
|
|
test_expect_success 'basic p4 labels' '
|
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
(
|
|
|
|
cd "$cli" &&
|
|
|
|
mkdir -p main &&
|
|
|
|
|
|
|
|
echo f1 >main/f1 &&
|
|
|
|
p4 add main/f1 &&
|
|
|
|
p4 submit -d "main/f1" &&
|
|
|
|
|
|
|
|
echo f2 >main/f2 &&
|
|
|
|
p4 add main/f2 &&
|
|
|
|
p4 submit -d "main/f2" &&
|
|
|
|
|
|
|
|
echo f3 >main/file_with_\$metachar &&
|
|
|
|
p4 add main/file_with_\$metachar &&
|
|
|
|
p4 submit -d "file with metachar" &&
|
|
|
|
|
|
|
|
p4 tag -l TAG_F1_ONLY main/f1 &&
|
|
|
|
p4 tag -l TAG_WITH\$_SHELL_CHAR main/... &&
|
2012-04-11 17:21:24 +02:00
|
|
|
p4 tag -l this_tag_will_be\ skipped main/... &&
|
2012-04-11 17:21:24 +02:00
|
|
|
|
|
|
|
echo f4 >main/f4 &&
|
|
|
|
p4 add main/f4 &&
|
|
|
|
p4 submit -d "main/f4" &&
|
|
|
|
|
|
|
|
p4 label -i <<-EOF &&
|
|
|
|
Label: TAG_LONG_LABEL
|
|
|
|
Description:
|
|
|
|
A Label first line
|
|
|
|
A Label second line
|
|
|
|
View: //depot/...
|
|
|
|
EOF
|
|
|
|
|
|
|
|
p4 tag -l TAG_LONG_LABEL ... &&
|
|
|
|
|
|
|
|
p4 labels ... &&
|
|
|
|
|
|
|
|
git p4 clone --dest="$git" //depot@all &&
|
|
|
|
cd "$git" &&
|
2012-04-11 17:21:24 +02:00
|
|
|
git config git-p4.labelImportRegexp ".*TAG.*" &&
|
2012-04-11 17:21:24 +02:00
|
|
|
git p4 sync --import-labels --verbose &&
|
|
|
|
|
|
|
|
git tag &&
|
|
|
|
git tag >taglist &&
|
|
|
|
test_line_count = 3 taglist &&
|
|
|
|
|
|
|
|
cd main &&
|
|
|
|
git checkout TAG_F1_ONLY &&
|
|
|
|
! test -f f2 &&
|
|
|
|
git checkout TAG_WITH\$_SHELL_CHAR &&
|
|
|
|
test -f f1 && test -f f2 && test -f file_with_\$metachar &&
|
|
|
|
|
|
|
|
git show TAG_LONG_LABEL | grep -q "A Label second line"
|
|
|
|
)
|
|
|
|
'
|
|
|
|
# Test some label corner cases:
|
|
|
|
#
|
|
|
|
# - two tags on the same file; both should be available
|
|
|
|
# - a tag that is only on one file; this kind of tag
|
|
|
|
# cannot be imported (at least not easily).
|
|
|
|
|
|
|
|
test_expect_success 'two labels on the same changelist' '
|
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
(
|
|
|
|
cd "$cli" &&
|
|
|
|
mkdir -p main &&
|
|
|
|
|
|
|
|
p4 edit main/f1 main/f2 &&
|
|
|
|
echo "hello world" >main/f1 &&
|
|
|
|
echo "not in the tag" >main/f2 &&
|
|
|
|
p4 submit -d "main/f[12]: testing two labels" &&
|
|
|
|
|
|
|
|
p4 tag -l TAG_F1_1 main/... &&
|
|
|
|
p4 tag -l TAG_F1_2 main/... &&
|
|
|
|
|
|
|
|
p4 labels ... &&
|
|
|
|
|
|
|
|
git p4 clone --dest="$git" //depot@all &&
|
|
|
|
cd "$git" &&
|
|
|
|
git p4 sync --import-labels &&
|
|
|
|
|
|
|
|
git tag | grep TAG_F1 &&
|
|
|
|
git tag | grep -q TAG_F1_1 &&
|
|
|
|
git tag | grep -q TAG_F1_2 &&
|
|
|
|
|
|
|
|
cd main &&
|
|
|
|
|
|
|
|
git checkout TAG_F1_1 &&
|
|
|
|
ls &&
|
|
|
|
test -f f1 &&
|
|
|
|
|
|
|
|
git checkout TAG_F1_2 &&
|
|
|
|
ls &&
|
|
|
|
test -f f1
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
# Export some git tags to p4
|
|
|
|
test_expect_success 'export git tags to p4' '
|
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
git p4 clone --dest="$git" //depot@all &&
|
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
git tag -m "A tag created in git:xyzzy" GIT_TAG_1 &&
|
|
|
|
echo "hello world" >main/f10 &&
|
|
|
|
git add main/f10 &&
|
|
|
|
git commit -m "Adding file for export test" &&
|
|
|
|
git config git-p4.skipSubmitEdit true &&
|
|
|
|
git p4 submit &&
|
|
|
|
git tag -m "Another git tag" GIT_TAG_2 &&
|
|
|
|
git tag LIGHTWEIGHT_TAG &&
|
|
|
|
git p4 rebase --import-labels --verbose &&
|
|
|
|
git p4 submit --export-labels --verbose
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd "$cli" &&
|
|
|
|
p4 sync ... &&
|
|
|
|
p4 labels ... | grep GIT_TAG_1 &&
|
|
|
|
p4 labels ... | grep GIT_TAG_2 &&
|
|
|
|
p4 labels ... | grep LIGHTWEIGHT_TAG &&
|
|
|
|
p4 label -o GIT_TAG_1 | grep "tag created in git:xyzzy" &&
|
|
|
|
p4 sync ...@GIT_TAG_1 &&
|
2018-07-02 02:24:04 +02:00
|
|
|
! test -f main/f10 &&
|
2012-04-11 17:21:24 +02:00
|
|
|
p4 sync ...@GIT_TAG_2 &&
|
|
|
|
test -f main/f10
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
# Export a tag from git where an affected file is deleted later on
|
|
|
|
# Need to create git tags after rebase, since only then can the
|
|
|
|
# git commits be mapped to p4 changelists.
|
|
|
|
test_expect_success 'export git tags to p4 with deletion' '
|
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
git p4 clone --dest="$git" //depot@all &&
|
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
git p4 sync --import-labels &&
|
|
|
|
echo "deleted file" >main/deleted_file &&
|
|
|
|
git add main/deleted_file &&
|
|
|
|
git commit -m "create deleted file" &&
|
|
|
|
git rm main/deleted_file &&
|
|
|
|
echo "new file" >main/f11 &&
|
|
|
|
git add main/f11 &&
|
|
|
|
git commit -m "delete the deleted file" &&
|
|
|
|
git config git-p4.skipSubmitEdit true &&
|
|
|
|
git p4 submit &&
|
|
|
|
git p4 rebase --import-labels --verbose &&
|
|
|
|
git tag -m "tag on deleted file" GIT_TAG_ON_DELETED HEAD~1 &&
|
|
|
|
git tag -m "tag after deletion" GIT_TAG_AFTER_DELETION HEAD &&
|
|
|
|
git p4 submit --export-labels --verbose
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd "$cli" &&
|
|
|
|
p4 sync ... &&
|
|
|
|
p4 sync ...@GIT_TAG_ON_DELETED &&
|
|
|
|
test -f main/deleted_file &&
|
|
|
|
p4 sync ...@GIT_TAG_AFTER_DELETION &&
|
|
|
|
! test -f main/deleted_file &&
|
|
|
|
echo "checking label contents" &&
|
|
|
|
p4 label -o GIT_TAG_ON_DELETED | grep "tag on deleted file"
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
# Create a tag in git that cannot be exported to p4
|
|
|
|
test_expect_success 'tag that cannot be exported' '
|
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
git p4 clone --dest="$git" //depot@all &&
|
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
git checkout -b a_branch &&
|
|
|
|
echo "hello" >main/f12 &&
|
|
|
|
git add main/f12 &&
|
|
|
|
git commit -m "adding f12" &&
|
|
|
|
git tag -m "tag on a_branch" GIT_TAG_ON_A_BRANCH &&
|
2020-11-19 00:44:44 +01:00
|
|
|
git checkout main &&
|
2012-04-11 17:21:24 +02:00
|
|
|
git p4 submit --export-labels
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd "$cli" &&
|
|
|
|
p4 sync ... &&
|
2019-03-13 13:24:19 +01:00
|
|
|
! p4 labels | grep GIT_TAG_ON_A_BRANCH
|
2012-04-11 17:21:24 +02:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2012-05-11 08:25:16 +02:00
|
|
|
test_expect_success 'use git config to enable import/export of tags' '
|
|
|
|
git p4 clone --verbose --dest="$git" //depot@all &&
|
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
git config git-p4.exportLabels true &&
|
|
|
|
git config git-p4.importLabels true &&
|
|
|
|
git tag CFG_A_GIT_TAG &&
|
|
|
|
git p4 rebase --verbose &&
|
|
|
|
git p4 submit --verbose &&
|
|
|
|
git tag &&
|
|
|
|
git tag | grep TAG_F1_1
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd "$cli" &&
|
|
|
|
p4 labels &&
|
|
|
|
p4 labels | grep CFG_A_GIT_TAG
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-08-27 09:18:56 +02:00
|
|
|
p4_head_revision() {
|
|
|
|
p4 changes -m 1 "$@" | awk '{print $2}'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Importing a label that references a P4 commit that
|
|
|
|
# has not been seen. The presence of a label on a commit
|
|
|
|
# we haven't seen should not cause git-p4 to fail. It should
|
|
|
|
# merely skip that label, and still import other labels.
|
2015-08-27 09:18:58 +02:00
|
|
|
test_expect_success 'importing labels with missing revisions' '
|
2015-08-27 09:18:56 +02:00
|
|
|
test_when_finished cleanup_git &&
|
|
|
|
(
|
|
|
|
rm -fr "$cli" "$git" &&
|
|
|
|
mkdir "$cli" &&
|
|
|
|
P4CLIENT=missing-revision &&
|
|
|
|
client_view "//depot/missing-revision/... //missing-revision/..." &&
|
|
|
|
cd "$cli" &&
|
|
|
|
>f1 && p4 add f1 && p4 submit -d "start" &&
|
|
|
|
|
|
|
|
p4 tag -l TAG_S0 ... &&
|
|
|
|
|
|
|
|
>f2 && p4 add f2 && p4 submit -d "second" &&
|
|
|
|
|
|
|
|
startrev=$(p4_head_revision //depot/missing-revision/...) &&
|
|
|
|
|
|
|
|
>f3 && p4 add f3 && p4 submit -d "third" &&
|
|
|
|
|
|
|
|
p4 edit f2 && date >f2 && p4 submit -d "change" f2 &&
|
|
|
|
|
|
|
|
endrev=$(p4_head_revision //depot/missing-revision/...) &&
|
|
|
|
|
|
|
|
p4 tag -l TAG_S1 ... &&
|
|
|
|
|
|
|
|
# we should skip TAG_S0 since it is before our startpoint,
|
|
|
|
# but pick up TAG_S1.
|
|
|
|
|
|
|
|
git p4 clone --dest="$git" --import-labels -v \
|
|
|
|
//depot/missing-revision/...@$startrev,$endrev &&
|
|
|
|
(
|
|
|
|
cd "$git" &&
|
|
|
|
git rev-parse TAG_S1 &&
|
|
|
|
! git rev-parse TAG_S0
|
|
|
|
)
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2012-04-11 17:21:24 +02:00
|
|
|
test_done
|