2010-07-02 23:20:47 +04:00
|
|
|
#!/bin/sh
|
|
|
|
|
2010-08-05 15:09:33 +04:00
|
|
|
test_description='CRLF merge conflict across text=auto change
|
|
|
|
|
|
|
|
* [master] remove .gitattributes
|
|
|
|
! [side] add line from b
|
|
|
|
--
|
|
|
|
+ [side] add line from b
|
|
|
|
* [master] remove .gitattributes
|
|
|
|
* [master^] add line from a
|
|
|
|
* [master~2] normalize file
|
|
|
|
*+ [side^] Initial
|
|
|
|
'
|
2010-07-02 23:20:47 +04:00
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
2010-12-14 21:32:12 +03:00
|
|
|
test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b
|
2010-09-17 17:16:01 +04:00
|
|
|
|
2016-06-28 11:01:13 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2010-07-02 23:20:47 +04:00
|
|
|
test_expect_success setup '
|
|
|
|
git config core.autocrlf false &&
|
2010-08-05 15:09:33 +04:00
|
|
|
|
2010-07-02 23:20:47 +04:00
|
|
|
echo first line | append_cr >file &&
|
|
|
|
echo first line >control_file &&
|
|
|
|
echo only line >inert_file &&
|
2010-08-05 15:09:33 +04:00
|
|
|
|
2010-07-02 23:20:47 +04:00
|
|
|
git add file control_file inert_file &&
|
2010-08-05 15:09:33 +04:00
|
|
|
test_tick &&
|
2010-07-02 23:20:47 +04:00
|
|
|
git commit -m "Initial" &&
|
|
|
|
git tag initial &&
|
|
|
|
git branch side &&
|
2010-08-05 15:09:33 +04:00
|
|
|
|
2010-07-02 23:20:47 +04:00
|
|
|
echo "* text=auto" >.gitattributes &&
|
2016-06-28 11:01:13 +03:00
|
|
|
echo first line >file &&
|
2010-07-02 23:20:47 +04:00
|
|
|
git add .gitattributes file &&
|
2010-08-05 15:09:33 +04:00
|
|
|
test_tick &&
|
2010-07-02 23:20:47 +04:00
|
|
|
git commit -m "normalize file" &&
|
2010-08-05 15:09:33 +04:00
|
|
|
|
2010-07-02 23:20:47 +04:00
|
|
|
echo same line | append_cr >>file &&
|
|
|
|
echo same line >>control_file &&
|
|
|
|
git add file control_file &&
|
2010-08-05 15:09:33 +04:00
|
|
|
test_tick &&
|
2010-07-02 23:20:47 +04:00
|
|
|
git commit -m "add line from a" &&
|
|
|
|
git tag a &&
|
2010-08-05 15:09:33 +04:00
|
|
|
|
2010-07-02 23:20:47 +04:00
|
|
|
git rm .gitattributes &&
|
|
|
|
rm file &&
|
|
|
|
git checkout file &&
|
2010-08-05 15:09:33 +04:00
|
|
|
test_tick &&
|
2010-07-02 23:20:47 +04:00
|
|
|
git commit -m "remove .gitattributes" &&
|
|
|
|
git tag c &&
|
2010-08-05 15:09:33 +04:00
|
|
|
|
2010-07-02 23:20:47 +04:00
|
|
|
git checkout side &&
|
|
|
|
echo same line | append_cr >>file &&
|
|
|
|
echo same line >>control_file &&
|
|
|
|
git add file control_file &&
|
2010-08-05 15:09:33 +04:00
|
|
|
test_tick &&
|
2010-07-02 23:20:47 +04:00
|
|
|
git commit -m "add line from b" &&
|
|
|
|
git tag b &&
|
2010-08-05 15:09:33 +04:00
|
|
|
|
2010-07-02 23:20:47 +04:00
|
|
|
git checkout master
|
|
|
|
'
|
|
|
|
|
2010-08-05 15:13:04 +04:00
|
|
|
test_expect_success 'set up fuzz_conflict() helper' '
|
|
|
|
fuzz_conflict() {
|
2010-09-17 17:16:01 +04:00
|
|
|
sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@"
|
2010-08-05 15:13:04 +04:00
|
|
|
}
|
|
|
|
'
|
|
|
|
|
2010-08-05 15:09:33 +04:00
|
|
|
test_expect_success 'Merge after setting text=auto' '
|
|
|
|
cat <<-\EOF >expected &&
|
|
|
|
first line
|
|
|
|
same line
|
|
|
|
EOF
|
|
|
|
|
2014-08-31 01:39:07 +04:00
|
|
|
if test_have_prereq NATIVE_CRLF; then
|
|
|
|
append_cr <expected >expected.temp &&
|
|
|
|
mv expected.temp expected
|
|
|
|
fi &&
|
2010-08-05 15:13:04 +04:00
|
|
|
git config merge.renormalize true &&
|
2010-08-05 15:09:33 +04:00
|
|
|
git rm -fr . &&
|
|
|
|
rm -f .gitattributes &&
|
2010-07-02 23:20:47 +04:00
|
|
|
git reset --hard a &&
|
|
|
|
git merge b &&
|
2016-06-28 11:01:13 +03:00
|
|
|
compare_files expected file
|
2010-07-02 23:20:47 +04:00
|
|
|
'
|
|
|
|
|
merge: avoid "safer crlf" during recording of merge results
When merge_recursive() decides what the correct blob object merge
result for a path should be, it uses update_file_flags() helper
function to write it out to a working tree file and then calls
add_cacheinfo(). The add_cacheinfo() function in turn calls
make_cache_entry() to create a new cache entry to replace the
higher-stage entries for the path that represents the conflict.
The make_cache_entry() function calls refresh_cache_entry() to fill
in the cached stat information. To mark a cache entry as
up-to-date, the data is re-read from the file in the working tree,
and goes through convert_to_git() conversion to be compared with the
blob object name the new cache entry records.
It is important to note that this happens while the higher-stage
entries, which are going to be replaced with the new entry, are
still in the index. Unfortunately, the convert_to_git() conversion
has a misguided "safer crlf" mechanism baked in, and looks at the
existing cache entry for the path to decide how to convert the
contents in the working tree file. If our side (i.e. stage#2)
records a text blob with CRLF in it, even when the system is
configured to record LF in blobs and convert them to CRLF upon
checkout (and back to LF upon checkin), the "safer crlf" mechanism
stops us doing so.
This especially poses a problem during a renormalizing merge, where
the merge result for the path is computed by first "normalizing" the
blobs involved in the merge by using convert_to_working_tree()
followed by convert_to_git() with "safer crlf" disabled. The merge
result that is computed correctly and fed to add_cacheinfo() via
update_file_flags() does _not_ match what refresh_cache_entry() sees
by converting the working tree file via convert_to_git().
We can work this around by not refreshing the new cache entry in
make_cache_entry() called by add_cacheinfo(). After add_cacheinfo()
adds the new entry, we can call refresh_cache_entry() on that,
knowing that addition of this new cache entry would have removed the
stale cache entries that had CRLF in stage #2 that were carried over
before the renormalizing merge started and will not interfere with
the correct recording of the result.
The test update was taken from a series by Torsten Bögershausen
that attempted to fix this with a different approach.
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Reviewed-by: Torsten Bögershausen <tboegi@web.de>
2016-07-08 20:59:15 +03:00
|
|
|
test_expect_success 'Merge addition of text=auto eol=LF' '
|
|
|
|
git config core.eol lf &&
|
2010-08-05 15:09:33 +04:00
|
|
|
cat <<-\EOF >expected &&
|
|
|
|
first line
|
|
|
|
same line
|
|
|
|
EOF
|
|
|
|
|
2010-08-05 15:13:04 +04:00
|
|
|
git config merge.renormalize true &&
|
2010-08-05 15:09:33 +04:00
|
|
|
git rm -fr . &&
|
|
|
|
rm -f .gitattributes &&
|
2010-07-02 23:20:47 +04:00
|
|
|
git reset --hard b &&
|
|
|
|
git merge a &&
|
2016-06-28 11:01:13 +03:00
|
|
|
compare_files expected file
|
2010-07-02 23:20:47 +04:00
|
|
|
'
|
|
|
|
|
merge: avoid "safer crlf" during recording of merge results
When merge_recursive() decides what the correct blob object merge
result for a path should be, it uses update_file_flags() helper
function to write it out to a working tree file and then calls
add_cacheinfo(). The add_cacheinfo() function in turn calls
make_cache_entry() to create a new cache entry to replace the
higher-stage entries for the path that represents the conflict.
The make_cache_entry() function calls refresh_cache_entry() to fill
in the cached stat information. To mark a cache entry as
up-to-date, the data is re-read from the file in the working tree,
and goes through convert_to_git() conversion to be compared with the
blob object name the new cache entry records.
It is important to note that this happens while the higher-stage
entries, which are going to be replaced with the new entry, are
still in the index. Unfortunately, the convert_to_git() conversion
has a misguided "safer crlf" mechanism baked in, and looks at the
existing cache entry for the path to decide how to convert the
contents in the working tree file. If our side (i.e. stage#2)
records a text blob with CRLF in it, even when the system is
configured to record LF in blobs and convert them to CRLF upon
checkout (and back to LF upon checkin), the "safer crlf" mechanism
stops us doing so.
This especially poses a problem during a renormalizing merge, where
the merge result for the path is computed by first "normalizing" the
blobs involved in the merge by using convert_to_working_tree()
followed by convert_to_git() with "safer crlf" disabled. The merge
result that is computed correctly and fed to add_cacheinfo() via
update_file_flags() does _not_ match what refresh_cache_entry() sees
by converting the working tree file via convert_to_git().
We can work this around by not refreshing the new cache entry in
make_cache_entry() called by add_cacheinfo(). After add_cacheinfo()
adds the new entry, we can call refresh_cache_entry() on that,
knowing that addition of this new cache entry would have removed the
stale cache entries that had CRLF in stage #2 that were carried over
before the renormalizing merge started and will not interfere with
the correct recording of the result.
The test update was taken from a series by Torsten Bögershausen
that attempted to fix this with a different approach.
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Reviewed-by: Torsten Bögershausen <tboegi@web.de>
2016-07-08 20:59:15 +03:00
|
|
|
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
|
|
|
|
'
|
|
|
|
|
2010-08-05 15:13:04 +04:00
|
|
|
test_expect_success 'Detect CRLF/LF conflict after setting text=auto' '
|
merge: avoid "safer crlf" during recording of merge results
When merge_recursive() decides what the correct blob object merge
result for a path should be, it uses update_file_flags() helper
function to write it out to a working tree file and then calls
add_cacheinfo(). The add_cacheinfo() function in turn calls
make_cache_entry() to create a new cache entry to replace the
higher-stage entries for the path that represents the conflict.
The make_cache_entry() function calls refresh_cache_entry() to fill
in the cached stat information. To mark a cache entry as
up-to-date, the data is re-read from the file in the working tree,
and goes through convert_to_git() conversion to be compared with the
blob object name the new cache entry records.
It is important to note that this happens while the higher-stage
entries, which are going to be replaced with the new entry, are
still in the index. Unfortunately, the convert_to_git() conversion
has a misguided "safer crlf" mechanism baked in, and looks at the
existing cache entry for the path to decide how to convert the
contents in the working tree file. If our side (i.e. stage#2)
records a text blob with CRLF in it, even when the system is
configured to record LF in blobs and convert them to CRLF upon
checkout (and back to LF upon checkin), the "safer crlf" mechanism
stops us doing so.
This especially poses a problem during a renormalizing merge, where
the merge result for the path is computed by first "normalizing" the
blobs involved in the merge by using convert_to_working_tree()
followed by convert_to_git() with "safer crlf" disabled. The merge
result that is computed correctly and fed to add_cacheinfo() via
update_file_flags() does _not_ match what refresh_cache_entry() sees
by converting the working tree file via convert_to_git().
We can work this around by not refreshing the new cache entry in
make_cache_entry() called by add_cacheinfo(). After add_cacheinfo()
adds the new entry, we can call refresh_cache_entry() on that,
knowing that addition of this new cache entry would have removed the
stale cache entries that had CRLF in stage #2 that were carried over
before the renormalizing merge started and will not interfere with
the correct recording of the result.
The test update was taken from a series by Torsten Bögershausen
that attempted to fix this with a different approach.
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Reviewed-by: Torsten Bögershausen <tboegi@web.de>
2016-07-08 20:59:15 +03:00
|
|
|
git config core.eol native &&
|
2014-08-31 01:39:07 +04:00
|
|
|
echo "<<<<<<<" >expected &&
|
merge: avoid "safer crlf" during recording of merge results
When merge_recursive() decides what the correct blob object merge
result for a path should be, it uses update_file_flags() helper
function to write it out to a working tree file and then calls
add_cacheinfo(). The add_cacheinfo() function in turn calls
make_cache_entry() to create a new cache entry to replace the
higher-stage entries for the path that represents the conflict.
The make_cache_entry() function calls refresh_cache_entry() to fill
in the cached stat information. To mark a cache entry as
up-to-date, the data is re-read from the file in the working tree,
and goes through convert_to_git() conversion to be compared with the
blob object name the new cache entry records.
It is important to note that this happens while the higher-stage
entries, which are going to be replaced with the new entry, are
still in the index. Unfortunately, the convert_to_git() conversion
has a misguided "safer crlf" mechanism baked in, and looks at the
existing cache entry for the path to decide how to convert the
contents in the working tree file. If our side (i.e. stage#2)
records a text blob with CRLF in it, even when the system is
configured to record LF in blobs and convert them to CRLF upon
checkout (and back to LF upon checkin), the "safer crlf" mechanism
stops us doing so.
This especially poses a problem during a renormalizing merge, where
the merge result for the path is computed by first "normalizing" the
blobs involved in the merge by using convert_to_working_tree()
followed by convert_to_git() with "safer crlf" disabled. The merge
result that is computed correctly and fed to add_cacheinfo() via
update_file_flags() does _not_ match what refresh_cache_entry() sees
by converting the working tree file via convert_to_git().
We can work this around by not refreshing the new cache entry in
make_cache_entry() called by add_cacheinfo(). After add_cacheinfo()
adds the new entry, we can call refresh_cache_entry() on that,
knowing that addition of this new cache entry would have removed the
stale cache entries that had CRLF in stage #2 that were carried over
before the renormalizing merge started and will not interfere with
the correct recording of the result.
The test update was taken from a series by Torsten Bögershausen
that attempted to fix this with a different approach.
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Reviewed-by: Torsten Bögershausen <tboegi@web.de>
2016-07-08 20:59:15 +03:00
|
|
|
echo first line >>expected &&
|
|
|
|
echo same line >>expected &&
|
|
|
|
echo ======= >>expected &&
|
2014-08-31 01:39:07 +04:00
|
|
|
echo first line | append_cr >>expected &&
|
|
|
|
echo same line | append_cr >>expected &&
|
|
|
|
echo ">>>>>>>" >>expected &&
|
2010-08-05 15:13:04 +04:00
|
|
|
git config merge.renormalize false &&
|
|
|
|
rm -f .gitattributes &&
|
|
|
|
git reset --hard a &&
|
|
|
|
test_must_fail git merge b &&
|
|
|
|
fuzz_conflict file >file.fuzzy &&
|
2016-06-28 11:01:13 +03:00
|
|
|
compare_files expected file.fuzzy
|
2010-08-05 15:13:04 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' '
|
2014-08-31 01:39:07 +04:00
|
|
|
echo "<<<<<<<" >expected &&
|
|
|
|
echo first line | append_cr >>expected &&
|
|
|
|
echo same line | append_cr >>expected &&
|
merge: avoid "safer crlf" during recording of merge results
When merge_recursive() decides what the correct blob object merge
result for a path should be, it uses update_file_flags() helper
function to write it out to a working tree file and then calls
add_cacheinfo(). The add_cacheinfo() function in turn calls
make_cache_entry() to create a new cache entry to replace the
higher-stage entries for the path that represents the conflict.
The make_cache_entry() function calls refresh_cache_entry() to fill
in the cached stat information. To mark a cache entry as
up-to-date, the data is re-read from the file in the working tree,
and goes through convert_to_git() conversion to be compared with the
blob object name the new cache entry records.
It is important to note that this happens while the higher-stage
entries, which are going to be replaced with the new entry, are
still in the index. Unfortunately, the convert_to_git() conversion
has a misguided "safer crlf" mechanism baked in, and looks at the
existing cache entry for the path to decide how to convert the
contents in the working tree file. If our side (i.e. stage#2)
records a text blob with CRLF in it, even when the system is
configured to record LF in blobs and convert them to CRLF upon
checkout (and back to LF upon checkin), the "safer crlf" mechanism
stops us doing so.
This especially poses a problem during a renormalizing merge, where
the merge result for the path is computed by first "normalizing" the
blobs involved in the merge by using convert_to_working_tree()
followed by convert_to_git() with "safer crlf" disabled. The merge
result that is computed correctly and fed to add_cacheinfo() via
update_file_flags() does _not_ match what refresh_cache_entry() sees
by converting the working tree file via convert_to_git().
We can work this around by not refreshing the new cache entry in
make_cache_entry() called by add_cacheinfo(). After add_cacheinfo()
adds the new entry, we can call refresh_cache_entry() on that,
knowing that addition of this new cache entry would have removed the
stale cache entries that had CRLF in stage #2 that were carried over
before the renormalizing merge started and will not interfere with
the correct recording of the result.
The test update was taken from a series by Torsten Bögershausen
that attempted to fix this with a different approach.
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Reviewed-by: Torsten Bögershausen <tboegi@web.de>
2016-07-08 20:59:15 +03:00
|
|
|
echo ======= >>expected &&
|
|
|
|
echo first line >>expected &&
|
|
|
|
echo same line >>expected &&
|
2014-08-31 01:39:07 +04:00
|
|
|
echo ">>>>>>>" >>expected &&
|
2010-08-05 15:13:04 +04:00
|
|
|
git config merge.renormalize false &&
|
|
|
|
rm -f .gitattributes &&
|
|
|
|
git reset --hard b &&
|
|
|
|
test_must_fail git merge a &&
|
|
|
|
fuzz_conflict file >file.fuzzy &&
|
2016-06-28 11:01:13 +03:00
|
|
|
compare_files expected file.fuzzy
|
2010-08-05 15:13:04 +04:00
|
|
|
'
|
|
|
|
|
2010-08-05 15:11:12 +04:00
|
|
|
test_expect_failure 'checkout -m after setting text=auto' '
|
|
|
|
cat <<-\EOF >expected &&
|
|
|
|
first line
|
|
|
|
same line
|
|
|
|
EOF
|
|
|
|
|
2010-08-05 15:13:04 +04:00
|
|
|
git config merge.renormalize true &&
|
2010-08-05 15:11:12 +04:00
|
|
|
git rm -fr . &&
|
|
|
|
rm -f .gitattributes &&
|
|
|
|
git reset --hard initial &&
|
|
|
|
git checkout a -- . &&
|
|
|
|
git checkout -m b &&
|
2016-06-28 11:01:13 +03:00
|
|
|
compare_files expected file
|
2010-08-05 15:11:12 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_failure 'checkout -m addition of text=auto' '
|
|
|
|
cat <<-\EOF >expected &&
|
|
|
|
first line
|
|
|
|
same line
|
|
|
|
EOF
|
|
|
|
|
2010-08-05 15:13:04 +04:00
|
|
|
git config merge.renormalize true &&
|
2010-08-05 15:11:12 +04:00
|
|
|
git rm -fr . &&
|
|
|
|
rm -f .gitattributes file &&
|
|
|
|
git reset --hard initial &&
|
|
|
|
git checkout b -- . &&
|
|
|
|
git checkout -m a &&
|
2016-06-28 11:01:13 +03:00
|
|
|
compare_files expected file
|
2010-08-05 15:11:12 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_failure 'cherry-pick patch from after text=auto was added' '
|
|
|
|
append_cr <<-\EOF >expected &&
|
|
|
|
first line
|
|
|
|
same line
|
|
|
|
EOF
|
|
|
|
|
2010-08-05 15:13:04 +04:00
|
|
|
git config merge.renormalize true &&
|
2010-08-05 15:11:12 +04:00
|
|
|
git rm -fr . &&
|
|
|
|
git reset --hard b &&
|
|
|
|
test_must_fail git cherry-pick a >err 2>&1 &&
|
|
|
|
grep "[Nn]othing added" err &&
|
2016-06-28 11:01:13 +03:00
|
|
|
compare_files expected file
|
2010-08-05 15:11:12 +04:00
|
|
|
'
|
|
|
|
|
2010-07-02 23:20:48 +04:00
|
|
|
test_expect_success 'Test delete/normalize conflict' '
|
2010-08-05 15:09:33 +04:00
|
|
|
git checkout -f side &&
|
|
|
|
git rm -fr . &&
|
|
|
|
rm -f .gitattributes &&
|
2010-07-02 23:20:47 +04:00
|
|
|
git reset --hard initial &&
|
|
|
|
git rm file &&
|
|
|
|
git commit -m "remove file" &&
|
|
|
|
git checkout master &&
|
|
|
|
git reset --hard a^ &&
|
|
|
|
git merge side
|
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|