git/branch: handle dirents changing between file and dir correctly (thanks cinap)

This commit is contained in:
Ori Bernstein 2024-09-13 16:28:32 +00:00
parent 9482f887f9
commit f63dcb4b9b
4 changed files with 59 additions and 9 deletions

View file

@ -84,6 +84,14 @@ if not {
}
echo $commit > .git/$new
for(d in $deleted){
if(! test -d $d){
rm -f $d
echo R NOQID 0 $d >> .git/INDEX9
}
}
for(m in $cleanpaths){
d=`$nl{basename -d $m}
mkdir -p $d
@ -114,13 +122,6 @@ for(ours in $dirtypaths){
merge1 $ours $ours $common $theirs
}
for(d in $deleted){
if(! test -d $d){
rm -f $d
echo R NOQID 0 $d >> .git/INDEX9
}
}
echo ref: $new > .git/HEAD
echo $new: `{git/query $new}
exit ''

View file

@ -0,0 +1,41 @@
#!/bin/rc
. util.rc
rm -fr scratch
mkdir -p scratch/repo1
echo @@ file-type change @@
@{
rfork ne
cd scratch/repo1
repo1=`{pwd}
$G/init
echo A > A
mkdir B
echo B > B/B
$G/add A
$G/commit -m 1 A
cd ..
$G/clone $repo1 repo2
cd repo2
repo2=`{pwd}
cd $repo1
rm A
rm -rf B
mkdir A
echo B > A/B
echo B > B
$G/add A/B
$G/add B
$G/commit -m 2 A/B B
# pull repo2 after file changed to directory in repo1
cd $repo2
$G/pull
# make sure A is the same in both repos
diff -r $repo1/A $repo2/A || echo fuck
}

View file

@ -4,6 +4,7 @@ TEST=\
add\
basic\
export\
ftype\
lca\
merge\
range

View file

@ -67,8 +67,15 @@ entcmp(void *pa, void *pb)
cb = '/';
return (ca > cb) ? 1 : -1;
}
if(ca == 0)
return 0;
if(ca == 0){
if(ae->mode & DMDIR)
ca = '/';
if(be->mode & DMDIR)
cb = '/';
if(ca == cb)
return 0;
return (ca > cb) ? 1 : -1;
}
}
}