ref: 6dcdf888b80f11a4ccf8109326f8b2a36fb173b2
parent: 16e6b176ee0404e48e2bd573727fe6ae92f7235e
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Aug 7 10:53:26 EDT 2021
git: add merge tests, clean up basic tests
--- /dev/null
+++ b/cmd/git/add.rc
@@ -1,0 +1,30 @@
+#!/bin/rc -e
+
+rm -fr addrepo
+mkdir -p addrepo
+
+echo @@ version1 @@
+@{
+rfork ne
+cd addrepo
+pwd=`{pwd}
+git/init
+mkdir dir
+mkdir another
+mkdir more
+touch a b c
+touch dir/a dir/b dir/c
+touch another/a another/b another/c
+touch more/a another/b another/c
+git/add a
+git/add $pwd/b
+git/add dir/a
+git/add $pwd/dir/b
+git/add more
+git/fs
+git/walk > ../actual.v1
+git/commit -m version1 .
+}
+
+diff -c actual.v1 expected.v1
+
--- /dev/null
+++ b/cmd/git/basic.rc
@@ -1,0 +1,67 @@
+#!/bin/rc
+
+. ../util.rc
+
+pwd=`{pwd}
+rm -fr scratch
+mkdir -p scratch/upstream
+
+echo @@ version1 @@
+@{
+ cd scratch/upstream
+ q git/init
+ echo version1 > file.txt
+ q git/add file.txt
+ q git/commit -m version1 file.txt
+}
+
+@{
+ cd scratch
+ q git/clone $pwd/scratch/upstream downstream
+}
+
+diff -c scratch/upstream/file.txt scratch/downstream/file.txt || die mismatch
+
+echo @@ version2 @@
+@{
+ cd scratch/upstream
+ echo version2 > file.txt
+ q git/commit -m version2 file.txt
+}
+@{
+ cd scratch/downstream
+ q git/pull
+}
+q diff -c scratch/upstream/file.txt scratch/downstream/file.txt || die mismatch
+
+echo @@ version3 @@
+@{
+ cd scratch/upstream
+ echo version3 > file2.txt
+ git/add file2.txt
+ q git/commit -m version3 file2.txt
+}
+@{
+ cd scratch/downstream
+ q git/pull
+}
+q diff -c scratch/upstream/file.txt scratch/downstream/file.txt || die mismatch
+q diff -c scratch/upstream/file2.txt scratch/downstream/file2.txt || die mismatch
+
+echo @@ version4 @@
+@{
+ cd scratch/upstream
+ echo version4 > file.txt
+ git/rm file2.txt
+ rm file2.txt
+ q git/commit -m version4 file.txt file2.txt
+}
+
+@{
+ cd scratch/downstream
+ q git/pull
+}
+q diff -c scratch/upstream/file.txt scratch/downstream/file.txt || die mismatch
+! test -e scratch/upstream/file2.txt || die mismatch
+! test -e scratch/downstream/file2.txt || die mismatch
+
--- a/cmd/git/git.rc
+++ /dev/null
@@ -1,57 +1,0 @@
-#!/bin/rc
-
-pwd=`{pwd}
-rm -fr repo
-mkdir -p repo/upstream
-
-echo @@ version1 @@
-@{cd repo/upstream
-git/init
-echo version1 > file.txt
-git/add file.txt
-git/commit -m version1 file.txt
-}
-
-@{cd repo
-git/clone $pwd/repo/upstream downstream
-}
-
-diff -c repo/upstream/file.txt repo/downstream/file.txt
-
-echo @@ version2 @@
-@{cd repo/upstream
-echo version2 > file.txt
-git/commit -m version2 file.txt
-}
-@{cd repo/downstream
-git/pull
-}
-diff -c repo/upstream/file.txt repo/downstream/file.txt
-
-echo @@ version3 @@
-@{cd repo/upstream
-echo version3 > file2.txt
-git/add file2.txt
-git/commit -m version3 file2.txt
-}
-@{cd repo/downstream
-git/pull
-}
-diff -c repo/upstream/file.txt repo/downstream/file.txt
-diff -c repo/upstream/file2.txt repo/downstream/file2.txt
-
-echo @@ version4 @@
-@{cd repo/upstream
-echo version4 > file.txt
-git/rm file2.txt
-rm file2.txt
-git/commit -m version4 file.txt file2.txt
-}
-
-@{cd repo/downstream
-git/pull
-}
-diff -c repo/upstream/file.txt repo/downstream/file.txt
-! test -e repo/upstream/file2.txt
-! test -e repo/downstream/file2.txt
-
--- /dev/null
+++ b/cmd/git/merge.rc
@@ -1,0 +1,84 @@
+#!/bin/rc
+
+. ../util.rc
+
+rm -fr scratch
+mkdir -p scratch
+cd scratch
+c='foo
+bar
+baz
+'
+
+# setup test repo
+@{
+ rfork ne
+ q git/init a
+
+ cd a
+ echo hello > a
+ echo goodbye > b
+ echo -n $c > c
+ q git/add a b c
+ q git/commit -m v1 .
+ cd ..
+ pwd
+ q git/clone `{pwd}^/a b
+}
+
+echo @@ merge different files @@
+@{
+ rfork ne
+ @{
+ cd a
+ echo x > a
+ q git/commit -m diverge1a a
+ }
+ @{
+ cd b
+ echo y > b
+ q git/commit -m diverge1b b
+ }
+
+ @{
+ cd b
+ qq git/pull
+ qq git/merge origin/front || status=''
+ q git/commit -m merged .
+ }
+}
+
+flag +x
+~ `{cat b/a} x || die merge 1.a
+~ `{cat b/b} y || die merge 1.b
+~ `''{cat b/c} $c || die merge 1.c
+
+echo @@ merge concurent edits @@
+@{
+ rfork ne
+ @{
+ cd a
+ echo quux >>c
+ q git/commit -m diverge2a c
+ }
+ @{
+ cd b
+ sed s/foo/FOO/ <c >c.new
+ mv c.new c
+ q git/commit -m diverge2b c
+
+ qq git/pull
+ qq git/merge origin/front
+ q git/commit -m merge c
+ }
+}
+
+c='FOO
+bar
+baz
+quux
+'
+~ `{cat b/a} x || die # commit from a
+~ `{cat b/b} y || die # commit from b
+~ `''{cat b/c} $c || die merge 1.c
+
--- a/cmd/git/mkfile
+++ b/cmd/git/mkfile
@@ -1,5 +1,7 @@
</$objtype/mkfile
-TEST=git
+TEST=\
+ basic\
+ merge
<../../regress
--- /dev/null
+++ b/cmd/util.rc
@@ -1,0 +1,14 @@
+fn q {
+ {$* > /tmp/out.$pid && rm /tmp/out.$pid} || cat /tmp/out
+}
+fn qq {
+ $* >/dev/null >[2]/dev/null
+}
+
+fn die {
+ st=$status
+ if(! ~ $st ''){
+ echo $* : $st
+ exit $* : $st
+ }
+}