* [9front] [PATCH] git/merge: fix merge if directory of merged file does not exist
@ 2022-04-19 11:27 igor
2022-04-19 13:51 ` ori
0 siblings, 1 reply; 3+ messages in thread
From: igor @ 2022-04-19 11:27 UTC (permalink / raw)
To: 9front; +Cc: ori, igor
[-- Attachment #1: Type: text/plain, Size: 2848 bytes --]
When merging from branch `front` to `test` the following test case
fails:
<testcase>
term% git/init merge.fail.git
term% cd merge.fail.git
term% mkdir A
term% cp /sys/src/cmd/xargs.c A/
term% git/add A/xargs.c
term% git/commit -m 'Meh...' A/xargs.c
heads/front: 5c36636e55aac3341ce42afee51b73106e8f1bc5
term% git/branch -n test
refs/heads/test: 5c36636e55aac3341ce42afee51b73106e8f1bc5
term% mkdir X
term% cp /sys/src/cmd/xargs.c X/
term% git/add X/xargs.c
term% git/commit -m 'Nein...' X/xargs.c
heads/test: 6dc8fecb03f15e1c018c51306d25b10919e8fbe4
term% git/branch front
refs/heads/front: 5c36636e55aac3341ce42afee51b73106e8f1bc5
term% mkdir A/B
term% cp /sys/src/cmd/xargs.c A/B/
term% git/add A/B/xargs.c
term% git/commit -m 'NeinNein...' A/B/xargs.c
heads/front: 3ca03f92152ed170e12b1ce2416ababbc18ffe54
term% git/branch test
refs/heads/test: 6dc8fecb03f15e1c018c51306d25b10919e8fbe4
term% mkdir X/Y
term% cp /sys/src/cmd/xargs.c X/Y/
term% git/add X/Y/xargs.c
term% git/commit -m 'NeinNeinNein...' X/Y/xargs.c
heads/test: a81075176ae6dbd6f501e6ea43fd878a29b9c60d
term% git/branch front
refs/heads/front: 3ca03f92152ed170e12b1ce2416ababbc18ffe54
term% git/branch test
refs/heads/test: a81075176ae6dbd6f501e6ea43fd878a29b9c60d
term% git/merge front
/sys/lib/git/common.rc:88: > can't create: ./A/B/.tmp: './A/B' does not exist
</testcase>
The problem is a redirect in `/sys/lib/git/common.rc` that assumes the
directory component of the file that contains the diff exists:
<sys/lib/git/common.rc>
fn merge1 {@{
rfork e
n=$pid
out=$1
ours=$2
base=$3
theirs=$4
tmp=$out.tmp
while(test -f $tmp){
tmp=$tmp.$n
n=`{echo $n + 1 | hoc}
}
if(! test -f $ours)
ours=/dev/null
if(! test -f $base)
base=/dev/null
if(! test -f $theirs)
theirs=/dev/null
if(! ape/diff3 -3 -m $ours $base $theirs > $tmp)
echo merge needed: $out >[1=2]
^^^^^^^^^^^^^^^^
IF THE FOLDER WHERE $tmp LIVES DOES NOT EXIST A REDIRECT
TO `> $tmp` FAILS TRIPPING UP THE MERGE
if(mergeperm $ours $base $theirs){
mv $tmp $out
git/add $out
chmod $mergedperms $out
}
if not {
rm -f $tmp $out
git/rm $out
}
}}
</sys/lib/git/common.rc>
A solution is to check if the folder exists and create it via `mkdir -p`
in case it doesn't.
Can someone have a look and confirm this is the right solution and not
a hack. If this is Ok plz let me know and I can push the fix.
Thanks.
Cheers,
Igor
---
diff 45f713a2bc2961b3c920aed616188591612da210 3c2aa08560fba8a69e09731e3e5d72f7003021e3
--- a/sys/lib/git/common.rc Sun Apr 17 23:25:04 2022
+++ b/sys/lib/git/common.rc Tue Apr 19 13:19:00 2022
@@ -76,7 +76,8 @@
tmp=$tmp.$n
n=`{echo $n + 1 | hoc}
}
-
+ if(! test -d `{basename -d $tmp})
+ mkdir -p `{basename -d $tmp}
if(! test -f $ours)
ours=/dev/null
if(! test -f $base)
[-- Attachment #2: git.merge.patch --]
[-- Type: text/plain, Size: 2843 bytes --]
From: Igor Böhm <igor@9lab.org>
Date: Tue, 19 Apr 2022 11:19:00 +0000
Subject: [PATCH] git/merge: fix merge if directory of merged file does not exist
When merging from `front` to `test` branch the following test
case fails:
<testcase>
term% git/init merge.fail.git
term% cd merge.fail.git
term% mkdir A
term% cp /sys/src/cmd/xargs.c A/
term% git/add A/xargs.c
term% git/commit -m 'Meh...' A/xargs.c
heads/front: 5c36636e55aac3341ce42afee51b73106e8f1bc5
term% git/branch -n test
refs/heads/test: 5c36636e55aac3341ce42afee51b73106e8f1bc5
term% mkdir X
term% cp /sys/src/cmd/xargs.c X/
term% git/add X/xargs.c
term% git/commit -m 'Nein...' X/xargs.c
heads/test: 6dc8fecb03f15e1c018c51306d25b10919e8fbe4
term% git/branch front
refs/heads/front: 5c36636e55aac3341ce42afee51b73106e8f1bc5
term% mkdir A/B
term% cp /sys/src/cmd/xargs.c A/B/
term% git/add A/B/xargs.c
term% git/commit -m 'NeinNein...' A/B/xargs.c
heads/front: 3ca03f92152ed170e12b1ce2416ababbc18ffe54
term% git/branch test
refs/heads/test: 6dc8fecb03f15e1c018c51306d25b10919e8fbe4
term% mkdir X/Y
term% cp /sys/src/cmd/xargs.c X/Y/
term% git/add X/Y/xargs.c
term% git/commit -m 'NeinNeinNein...' X/Y/xargs.c
heads/test: a81075176ae6dbd6f501e6ea43fd878a29b9c60d
term% git/branch front
refs/heads/front: 3ca03f92152ed170e12b1ce2416ababbc18ffe54
term% git/branch test
refs/heads/test: a81075176ae6dbd6f501e6ea43fd878a29b9c60d
term% git/merge front
/sys/lib/git/common.rc:88: > can't create: ./A/B/.tmp: './A/B' does not exist
</testcase>
The problem is a redirect in `/sys/lib/git/common.rc` that assumes the
directory component of the file that contains the diff exists:
<sys/lib/git/common.rc>
fn merge1 {@{
rfork e
n=$pid
out=$1
ours=$2
base=$3
theirs=$4
tmp=$out.tmp
while(test -f $tmp){
tmp=$tmp.$n
n=`{echo $n + 1 | hoc}
}
if(! test -f $ours)
ours=/dev/null
if(! test -f $base)
base=/dev/null
if(! test -f $theirs)
theirs=/dev/null
if(! ape/diff3 -3 -m $ours $base $theirs > $tmp)
echo merge needed: $out >[1=2]
^^^^^^^^^^^^^^^^
IF THE FOLDER WHERE $tmp LIVES DOES NOT EXIST A REDIRECT
TO `> $tmp` FAILS TRIPPING UP THE MERGE
if(mergeperm $ours $base $theirs){
mv $tmp $out
git/add $out
chmod $mergedperms $out
}
if not {
rm -f $tmp $out
git/rm $out
}
}}
</sys/lib/git/common.rc>
A solution is to check if the folder exists and create it via `mkdir -p`
in case it doesn't.
---
diff 45f713a2bc2961b3c920aed616188591612da210 3c2aa08560fba8a69e09731e3e5d72f7003021e3
--- a/sys/lib/git/common.rc Sun Apr 17 23:25:04 2022
+++ b/sys/lib/git/common.rc Tue Apr 19 13:19:00 2022
@@ -76,7 +76,8 @@
tmp=$tmp.$n
n=`{echo $n + 1 | hoc}
}
-
+ if(! test -d `{basename -d $tmp})
+ mkdir -p `{basename -d $tmp}
if(! test -f $ours)
ours=/dev/null
if(! test -f $base)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9front] [PATCH] git/merge: fix merge if directory of merged file does not exist
2022-04-19 11:27 [9front] [PATCH] git/merge: fix merge if directory of merged file does not exist igor
@ 2022-04-19 13:51 ` ori
2022-04-19 13:58 ` igor
0 siblings, 1 reply; 3+ messages in thread
From: ori @ 2022-04-19 13:51 UTC (permalink / raw)
To: 9front; +Cc: igor, ori
Quoth igor@9lab.org:
> When merging from branch `front` to `test` the following test case
> fails:
>
> <snip>
>
> A solution is to check if the folder exists and create it via `mkdir -p`
> in case it doesn't.
>
> Can someone have a look and confirm this is the right solution and not
> a hack. If this is Ok plz let me know and I can push the fix.
>
I've got that added in my patch queue, slightly differently;
because mkdir -p always succeeds, there's no need for the if.
> -
> + if(! test -d `{basename -d $tmp})
> + mkdir -p `{basename -d $tmp}
> if(! test -f $ours)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9front] [PATCH] git/merge: fix merge if directory of merged file does not exist
2022-04-19 13:51 ` ori
@ 2022-04-19 13:58 ` igor
0 siblings, 0 replies; 3+ messages in thread
From: igor @ 2022-04-19 13:58 UTC (permalink / raw)
To: 9front; +Cc: igor, ori
Quoth ori@eigenstate.org:
> Quoth igor@9lab.org:
> > When merging from branch `front` to `test` the following test case
> > fails:
> >
> > <snip>
> >
> > A solution is to check if the folder exists and create it via `mkdir -p`
> > in case it doesn't.
> >
> > Can someone have a look and confirm this is the right solution and not
> > a hack. If this is Ok plz let me know and I can push the fix.
> >
>
> I've got that added in my patch queue, slightly differently;
> because mkdir -p always succeeds, there's no need for the if.
Excellent, then I will wait for you to push that one ☺
There is one more instance of mkdir -p in gitup, you probably have that
one converted as well to remove the test (see highlighted part):
fn gitup{
gitroot=`{git/conf -r >[2]/dev/null}
if(~ $#gitroot 0)
die 'not a git repository'
gitfs=$gitroot/.git/fs
gitrel=`{pwd | drop $gitroot | sed 's@^/@@'}
if(~ $#gitrel 0)
gitrel='.'
cd $gitroot
startfs=()
if(! test -d $gitfs)
mkdir -p $gitfs
^^^^^^^^^^^^^^^^^^^^^^^^^^
if(! test -e $gitfs/ctl)
startfs=true
if(! grep -s '^repo '$gitroot'$' $gitfs/ctl >[2]/dev/null)
startfs=true
if(~ $#startfs 1)
git/fs
if not
status=''
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-19 14:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-19 11:27 [9front] [PATCH] git/merge: fix merge if directory of merged file does not exist igor
2022-04-19 13:51 ` ori
2022-04-19 13:58 ` igor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).