Merge branch 'jc/read-tree'

* jc/read-tree:
  t6022: ignoring untracked files by merge-recursive when they do not matter
  merge-recursive: adjust to loosened "working file clobbered" check
  merge-recursive: make a few functions static.
  merge-recursive: use abbreviated commit object name.
  merge: loosen overcautious "working file will be lost" check.
This commit is contained in:
Junio C Hamano
2006-11-07 15:41:34 -08:00
5 changed files with 244 additions and 60 deletions

53
t/t1004-read-tree-m-u-wf.sh Executable file
View File

@ -0,0 +1,53 @@
#!/bin/sh
test_description='read-tree -m -u checks working tree files'
. ./test-lib.sh
# two-tree test
test_expect_success 'two-way setup' '
echo >file1 file one &&
echo >file2 file two &&
git update-index --add file1 file2 &&
git commit -m initial &&
git branch side &&
git tag -f branch-point &&
echo file2 is not tracked on the master anymore &&
rm -f file2 &&
git update-index --remove file2 &&
git commit -a -m "master removes file2"
'
test_expect_success 'two-way not clobbering' '
echo >file2 master creates untracked file2 &&
if err=`git read-tree -m -u master side 2>&1`
then
echo should have complained
false
else
echo "happy to see $err"
fi
'
# three-tree test
test_expect_success 'three-way not complaining' '
rm -f file2 &&
git checkout side &&
echo >file3 file three &&
git update-index --add file3 &&
git commit -a -m "side adds file3" &&
git checkout master &&
echo >file2 file two is untracked on the master side &&
git-read-tree -m -u branch-point master side
'
test_done

View File

@ -42,15 +42,20 @@ O OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
EOF
git add A M &&
git commit -m initial &&
git commit -m "initial has A and M" &&
git branch white &&
git branch red &&
git branch blue &&
git branch yellow &&
sed -e "/^g /s/.*/g : master changes a line/" <A >A+ &&
mv A+ A &&
git commit -a -m "master updates A" &&
git checkout yellow &&
rm -f M &&
git commit -a -m "yellow removes M" &&
git checkout white &&
sed -e "/^g /s/.*/g : white changes a line/" <A >B &&
sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
@ -79,27 +84,27 @@ test_expect_success 'pull renaming branch into unrenaming one' \
git show-branch
git pull . white && {
echo "BAD: should have conflicted"
exit 1
return 1
}
git ls-files -s
test "$(git ls-files -u B | wc -l)" -eq 3 || {
echo "BAD: should have left stages for B"
exit 1
return 1
}
test "$(git ls-files -s N | wc -l)" -eq 1 || {
echo "BAD: should have merged N"
exit 1
return 1
}
sed -ne "/^g/{
p
q
}" B | grep master || {
echo "BAD: should have listed our change first"
exit 1
return 1
}
test "$(git diff white N | wc -l)" -eq 0 || {
echo "BAD: should have taken colored branch"
exit 1
return 1
}
'
@ -110,26 +115,26 @@ test_expect_success 'pull renaming branch into another renaming one' \
git checkout red
git pull . white && {
echo "BAD: should have conflicted"
exit 1
return 1
}
test "$(git ls-files -u B | wc -l)" -eq 3 || {
echo "BAD: should have left stages"
exit 1
return 1
}
test "$(git ls-files -s N | wc -l)" -eq 1 || {
echo "BAD: should have merged N"
exit 1
return 1
}
sed -ne "/^g/{
p
q
}" B | grep red || {
echo "BAD: should have listed our change first"
exit 1
return 1
}
test "$(git diff white N | wc -l)" -eq 0 || {
echo "BAD: should have taken colored branch"
exit 1
return 1
}
'
@ -139,26 +144,26 @@ test_expect_success 'pull unrenaming branch into renaming one' \
git show-branch
git pull . master && {
echo "BAD: should have conflicted"
exit 1
return 1
}
test "$(git ls-files -u B | wc -l)" -eq 3 || {
echo "BAD: should have left stages"
exit 1
return 1
}
test "$(git ls-files -s N | wc -l)" -eq 1 || {
echo "BAD: should have merged N"
exit 1
return 1
}
sed -ne "/^g/{
p
q
}" B | grep red || {
echo "BAD: should have listed our change first"
exit 1
return 1
}
test "$(git diff white N | wc -l)" -eq 0 || {
echo "BAD: should have taken colored branch"
exit 1
return 1
}
'
@ -168,35 +173,149 @@ test_expect_success 'pull conflicting renames' \
git show-branch
git pull . blue && {
echo "BAD: should have conflicted"
exit 1
return 1
}
test "$(git ls-files -u A | wc -l)" -eq 1 || {
echo "BAD: should have left a stage"
exit 1
return 1
}
test "$(git ls-files -u B | wc -l)" -eq 1 || {
echo "BAD: should have left a stage"
exit 1
return 1
}
test "$(git ls-files -u C | wc -l)" -eq 1 || {
echo "BAD: should have left a stage"
exit 1
return 1
}
test "$(git ls-files -s N | wc -l)" -eq 1 || {
echo "BAD: should have merged N"
exit 1
return 1
}
sed -ne "/^g/{
p
q
}" B | grep red || {
echo "BAD: should have listed our change first"
exit 1
return 1
}
test "$(git diff white N | wc -l)" -eq 0 || {
echo "BAD: should have taken colored branch"
exit 1
return 1
}
'
test_expect_success 'interference with untracked working tree file' '
git reset --hard
git show-branch
echo >A this file should not matter
git pull . white && {
echo "BAD: should have conflicted"
return 1
}
test -f A || {
echo "BAD: should have left A intact"
return 1
}
'
test_expect_success 'interference with untracked working tree file' '
git reset --hard
git checkout white
git show-branch
rm -f A
echo >A this file should not matter
git pull . red && {
echo "BAD: should have conflicted"
return 1
}
test -f A || {
echo "BAD: should have left A intact"
return 1
}
'
test_expect_success 'interference with untracked working tree file' '
git reset --hard
rm -f A M
git checkout -f master
git tag -f anchor
git show-branch
git pull . yellow || {
echo "BAD: should have cleanly merged"
return 1
}
test -f M && {
echo "BAD: should have removed M"
return 1
}
git reset --hard anchor
'
test_expect_success 'updated working tree file should prevent the merge' '
git reset --hard
rm -f A M
git checkout -f master
git tag -f anchor
git show-branch
echo >>M one line addition
cat M >M.saved
git pull . yellow && {
echo "BAD: should have complained"
return 1
}
diff M M.saved || {
echo "BAD: should have left M intact"
return 1
}
rm -f M.saved
'
test_expect_success 'updated working tree file should prevent the merge' '
git reset --hard
rm -f A M
git checkout -f master
git tag -f anchor
git show-branch
echo >>M one line addition
cat M >M.saved
git update-index M
git pull . yellow && {
echo "BAD: should have complained"
return 1
}
diff M M.saved || {
echo "BAD: should have left M intact"
return 1
}
rm -f M.saved
'
test_expect_success 'interference with untracked working tree file' '
git reset --hard
rm -f A M
git checkout -f yellow
git tag -f anchor
git show-branch
echo >M this file should not matter
git pull . master || {
echo "BAD: should have cleanly merged"
return 1
}
test -f M || {
echo "BAD: should have left M intact"
return 1
}
git ls-files -s | grep M && {
echo "BAD: M must be untracked in the result"
return 1
}
git reset --hard anchor
'
test_done