sapling/tests/test-subrepos

137 lines
4.2 KiB
Bash

#!/bin/sh
# Fails for some reason, need to investigate
# "$TESTDIR/hghave" git || exit 80
# bail if the user does not have dulwich
python -c 'import dulwich, dulwich.repo' || exit 80
# bail early if the user is already running git-daemon
echo hi | nc localhost 9418 2>/dev/null && exit 80
echo "[extensions]" >> $HGRCPATH
echo "hggit=$(echo $(dirname $(dirname $0)))/hggit" >> $HGRCPATH
echo 'hgext.bookmarks =' >> $HGRCPATH
GIT_AUTHOR_NAME='test'; export GIT_AUTHOR_NAME
GIT_AUTHOR_EMAIL='test@example.org'; export GIT_AUTHOR_EMAIL
GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0000"; export GIT_AUTHOR_DATE
GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; export GIT_COMMITTER_NAME
GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; export GIT_COMMITTER_EMAIL
GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; export GIT_COMMITTER_DATE
count=10
gitcommit()
{
GIT_AUTHOR_DATE="2007-01-01 00:00:$count +0000"
GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
git commit "$@" >/dev/null 2>/dev/null || echo "git commit error"
count=`expr $count + 1`
}
hgcommit()
{
HGDATE="2007-01-01 00:00:$count +0000"
hg commit -d "$HGDATE" "$@" >/dev/null 2>/dev/null || echo "hg commit error"
count=`expr $count + 1`
}
mkdir gitsubrepo
cd gitsubrepo
git init | python -c "import sys; print sys.stdin.read().replace('$(dirname $(pwd))/', '')"
echo beta > beta
git add beta
gitcommit -m 'add beta'
cd ..
mkdir gitrepo1
cd gitrepo1
git init | python -c "import sys; print sys.stdin.read().replace('$(dirname $(pwd))/', '')"
echo alpha > alpha
git add alpha
gitcommit -m 'add alpha'
git submodule add ../gitsubrepo subrepo1
gitcommit -m 'add subrepo1'
git submodule add ../gitsubrepo xyz/subrepo2
gitcommit -m 'add subrepo2'
# we are going to push to this repo from our hg clone,
# allow commits despite working copy presense
git config receive.denyCurrentBranch ignore
cd ..
echo
git daemon --base-path="$(pwd)"\
--listen=localhost\
--export-all\
--pid-file="$DAEMON_PIDS" \
--detach --reuseaddr \
--enable=receive-pack
echo % Ensure gitlinks are transformed to .hgsubstate on hg pull from git
hg clone git://localhost/gitrepo1 hgrepo
cd hgrepo
hg bookmarks -f -r default master
# 1. Ensure gitlinks are transformed to .hgsubstate on hg <- git pull
# Synopsis: clone, check .hgsub and .hgsubstate are in place
echo % .hgsub shall list two [git] subrepos
cat .hgsub
echo % .hgsubstate shall list two idenitcal revisions
cat .hgsubstate
echo % hg status shall NOT report .hgsub and .hgsubstate as untracked - either ignored or unmodified
hg status --unknown .hgsub .hgsubstate
hg status --modified .hgsub .hgsubstate
cd ..
echo
# 2. Check gitmodules are preserved during hg -> git push
# Synopsis: modify git sumodule, update hg subrepo to this new revision,
# hg commit, push to git, see gitlinks are correct (preserved for subrepo1,
# and updated for subrepo2
echo % Check gitmodules are preserved during hg push to git
cd gitsubrepo
echo gamma > gamma
git add gamma
gitcommit -m 'add gamma'
cd ..
cd hgrepo
cd xyz/subrepo2
git pull
cd ../..
echo xxx >> alpha
hg commit -m 'Update subrepo2 from hg'
hg push
cd ..
cd gitrepo1
echo % there shall be two gitlink entries, with values matching that in .hgsubstate
git ls-tree -r HEAD^{tree} | grep 'commit'
# bring working copy to HEAD state (it's not bare repo)
git reset --hard
cd ..
echo
# 3. Check .hgsub and .hgsubstate from git repository are merged, not overwritten
# Synopsis: add hg repo to become a subrepo for existing repo.
# Commit .hgsub and .hgsubstate in gitrepo, that point to newly added hg repo
# pull changes to exising hgrepo, see preserved values
echo Check .hgsub and .hgsubstate from git repository are merged, not overwritten
hg init hgsub
cd hgsub
echo delta > delta
hg add delta
hgcommit -m "add delta"
echo "`hg tip --template '{node}'` hgsub" > ../gitrepo1/.hgsubstate
echo "hgsub = $(pwd)" > ../gitrepo1/.hgsub
cd ../gitrepo1
git add .hgsubstate .hgsub
gitcommit -m "Test3. Prepare .hgsub and .hgsubstate sources"
cd ../hgrepo
hg pull
hg checkout -C | sed s_$(dirname $(pwd))_TEMPLOCATION_
cd ..
echo % pull shall bring .hgsub entry which was added to the git repo
cat hgrepo/.hgsub | sed s_$(pwd)_TEMPLOCATION_
echo % .hgsubstate shall list revision of the subrepo added through git repo
cat hgrepo/.hgsubstate | sed s_$(pwd)_TEMPLOCATION_