mirror of
https://github.com/git/git.git
synced 2024-12-12 03:14:11 +08:00
2f64da0790
In git-restore we need to free the pathspec and pathspec_from_file values from the struct checkout_opts. A simple fix could be to free them in cmd_restore, after the call to checkout_main returns, like we are doing [1][2] in the sibling function cmd_checkout. However, we can do even better. We have git-switch and git-restore, both of them spin-offs[3][4] of git-checkout. All three are implemented as thin wrappers around checkout_main. Considering this, it makes a lot of sense to do the cleanup closer to checkout_main. Move the cleanups, including the new_branch_info variable, to checkout_main. As a consequence, mark: t2070, t2071, t2072 and t6418 as leak-free. [1]9081a421a6
(checkout: fix "branch info" memory leaks, 2021-11-16) [2]7ce4088ab7
(parse-options: consistently allocate memory in fix_filename(), 2023-03-04) [3]d787d311db
(checkout: split part of it to new command 'switch', 2019-03-29) [4]46e91b663b
(checkout: split part of it to new command 'restore', 2019-04-25) Signed-off-by: Rubén Justo <rjusto@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
235 lines
5.2 KiB
Bash
Executable File
235 lines
5.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='CRLF merge conflict across text=auto change
|
|
|
|
* [main] remove .gitattributes
|
|
! [side] add line from b
|
|
--
|
|
+ [side] add line from b
|
|
* [main] remove .gitattributes
|
|
* [main^] add line from a
|
|
* [main~2] normalize file
|
|
*+ [side^] Initial
|
|
'
|
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
|
. ./test-lib.sh
|
|
|
|
test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b
|
|
|
|
compare_files () {
|
|
tr '\015\000' QN <"$1" >"$1".expect &&
|
|
tr '\015\000' QN <"$2" >"$2".actual &&
|
|
test_cmp "$1".expect "$2".actual &&
|
|
rm "$1".expect "$2".actual
|
|
}
|
|
|
|
test_expect_success setup '
|
|
git config core.autocrlf false &&
|
|
|
|
echo first line | append_cr >file &&
|
|
echo first line >control_file &&
|
|
echo only line >inert_file &&
|
|
|
|
git add file control_file inert_file &&
|
|
test_tick &&
|
|
git commit -m "Initial" &&
|
|
git tag initial &&
|
|
git branch side &&
|
|
|
|
echo "* text=auto" >.gitattributes &&
|
|
echo first line >file &&
|
|
git add .gitattributes file &&
|
|
test_tick &&
|
|
git commit -m "normalize file" &&
|
|
|
|
echo same line | append_cr >>file &&
|
|
echo same line >>control_file &&
|
|
git add file control_file &&
|
|
test_tick &&
|
|
git commit -m "add line from a" &&
|
|
git tag a &&
|
|
|
|
git rm .gitattributes &&
|
|
rm file &&
|
|
git checkout file &&
|
|
test_tick &&
|
|
git commit -m "remove .gitattributes" &&
|
|
git tag c &&
|
|
|
|
git checkout side &&
|
|
echo same line | append_cr >>file &&
|
|
echo same line >>control_file &&
|
|
git add file control_file &&
|
|
test_tick &&
|
|
git commit -m "add line from b" &&
|
|
git tag b &&
|
|
|
|
git checkout main
|
|
'
|
|
|
|
test_expect_success 'set up fuzz_conflict() helper' '
|
|
fuzz_conflict() {
|
|
sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@"
|
|
}
|
|
'
|
|
|
|
test_expect_success 'Merge after setting text=auto' '
|
|
cat <<-\EOF >expected &&
|
|
first line
|
|
same line
|
|
EOF
|
|
|
|
if test_have_prereq NATIVE_CRLF; then
|
|
append_cr <expected >expected.temp &&
|
|
mv expected.temp expected
|
|
fi &&
|
|
git config merge.renormalize true &&
|
|
git rm -fr . &&
|
|
rm -f .gitattributes &&
|
|
git reset --hard a &&
|
|
git merge b &&
|
|
compare_files expected file
|
|
'
|
|
|
|
test_expect_success 'Merge addition of text=auto eol=LF' '
|
|
git config core.eol lf &&
|
|
cat <<-\EOF >expected &&
|
|
first line
|
|
same line
|
|
EOF
|
|
|
|
git config merge.renormalize true &&
|
|
git rm -fr . &&
|
|
rm -f .gitattributes &&
|
|
git reset --hard b &&
|
|
git merge a &&
|
|
compare_files expected file
|
|
'
|
|
|
|
test_expect_success 'Merge addition of text=auto eol=CRLF' '
|
|
git config core.eol crlf &&
|
|
cat <<-\EOF >expected &&
|
|
first line
|
|
same line
|
|
EOF
|
|
|
|
append_cr <expected >expected.temp &&
|
|
mv expected.temp expected &&
|
|
git config merge.renormalize true &&
|
|
git rm -fr . &&
|
|
rm -f .gitattributes &&
|
|
git reset --hard b &&
|
|
echo >&2 "After git reset --hard b" &&
|
|
git ls-files -s --eol >&2 &&
|
|
git merge a &&
|
|
compare_files expected file
|
|
'
|
|
|
|
test_expect_success 'Detect CRLF/LF conflict after setting text=auto' '
|
|
git config core.eol native &&
|
|
echo "<<<<<<<" >expected &&
|
|
echo first line >>expected &&
|
|
echo same line >>expected &&
|
|
echo ======= >>expected &&
|
|
echo first line | append_cr >>expected &&
|
|
echo same line | append_cr >>expected &&
|
|
echo ">>>>>>>" >>expected &&
|
|
git config merge.renormalize false &&
|
|
rm -f .gitattributes &&
|
|
git reset --hard a &&
|
|
test_must_fail git merge b &&
|
|
fuzz_conflict file >file.fuzzy &&
|
|
compare_files expected file.fuzzy
|
|
'
|
|
|
|
test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' '
|
|
echo "<<<<<<<" >expected &&
|
|
echo first line | append_cr >>expected &&
|
|
echo same line | append_cr >>expected &&
|
|
echo ======= >>expected &&
|
|
echo first line >>expected &&
|
|
echo same line >>expected &&
|
|
echo ">>>>>>>" >>expected &&
|
|
git config merge.renormalize false &&
|
|
rm -f .gitattributes &&
|
|
git reset --hard b &&
|
|
test_must_fail git merge a &&
|
|
fuzz_conflict file >file.fuzzy &&
|
|
compare_files expected file.fuzzy
|
|
'
|
|
|
|
test_expect_success 'checkout -m after setting text=auto' '
|
|
cat <<-\EOF >expected &&
|
|
first line
|
|
same line
|
|
EOF
|
|
|
|
git config merge.renormalize true &&
|
|
git rm -fr . &&
|
|
rm -f .gitattributes &&
|
|
git reset --hard initial &&
|
|
git restore --source=a -- . &&
|
|
git checkout -m b &&
|
|
git diff --no-index --ignore-cr-at-eol expected file
|
|
'
|
|
|
|
test_expect_success 'checkout -m addition of text=auto' '
|
|
cat <<-\EOF >expected &&
|
|
first line
|
|
same line
|
|
EOF
|
|
|
|
git config merge.renormalize true &&
|
|
git rm -fr . &&
|
|
rm -f .gitattributes file &&
|
|
git reset --hard initial &&
|
|
git restore --source=b -- . &&
|
|
git checkout -m a &&
|
|
git diff --no-index --ignore-cr-at-eol expected file
|
|
'
|
|
|
|
test_expect_success 'Test delete/normalize conflict' '
|
|
git checkout -f side &&
|
|
git rm -fr . &&
|
|
rm -f .gitattributes &&
|
|
git reset --hard initial &&
|
|
git rm file &&
|
|
git commit -m "remove file" &&
|
|
git checkout main &&
|
|
git reset --hard a^ &&
|
|
git merge side &&
|
|
test_path_is_missing file
|
|
'
|
|
|
|
test_expect_success 'rename/delete vs. renormalization' '
|
|
git init subrepo &&
|
|
(
|
|
cd subrepo &&
|
|
echo foo >oldfile &&
|
|
git add oldfile &&
|
|
git commit -m original &&
|
|
|
|
git branch rename &&
|
|
git branch nuke &&
|
|
|
|
git checkout rename &&
|
|
git mv oldfile newfile &&
|
|
git commit -m renamed &&
|
|
|
|
git checkout nuke &&
|
|
git rm oldfile &&
|
|
git commit -m deleted &&
|
|
|
|
git checkout rename^0 &&
|
|
test_must_fail git -c merge.renormalize=true merge nuke >out &&
|
|
|
|
grep "rename/delete" out
|
|
)
|
|
'
|
|
|
|
test_done
|