sapling/tests/test-bookmark-workflow.t
David M. Carr 33f1efdddf tests: extract git command-line client and dulwich requirements into testutil
One or both of these requirements were in almost every test in exactly the same
way.  Now, these checks are performed in every test that uses the testutil.
This makes it easier for test authors to add these checks into new tests (just
add a reference to the testutil, which you'd probably want anyway).

We considered having each test declare their requirements (currently, either
"git" or "dulwich"), but in this case, preferred the simplicity of having the
check always performed (even if a particular test doesn't need one or the
other).  You can't perform any meaningful testing of Hg-Git without both of
these dependencies properly configured.  The main value to checking for them
in the tests (rather than just letting the tests fail) is that it gives a
meaningful error message to help people figure out how to fix their environment.
In the case that either git or dulwich is missing, the information will be
just as clearly conveyed regardless of whether its all the tests that are
skipped, or just most of them.

I didn't add dulwich to hghave (even though this is clearly the sort of thing
that hghave is intended for) because hghave is currently pulled from Mercurial
completely unchanged, and it's probably best to keep it that way.

Tested by running the tests in three configurations:
 * No dulwich installed (ran 0, skipped 28, failed 0, output:
        Skipped *: missing feature: dulwich)
 * Bad git on path (ran 1, skipped 27, failed 0, output:
        Skipped *: missing feature: git command line client)
 * Working git and correct version of dulwich installed
        (ran 28, skipped 0, failed 0)

Thanks to Felipe Contreras for the idea to extract this logic into a library.
2012-11-03 19:11:50 -04:00

169 lines
5.1 KiB
Perl

This test demonstrates how Hg works with remote Hg bookmarks compared with
remote branches via Hg-Git. Ideally, they would behave identically. In
practice, some differences are unavoidable, but we should try to minimize
them.
This test should not bother testing the behavior of bookmark creation,
deletion, activation, deactivation, etc. These behaviors, while important to
the end user, don't vary at all when Hg-Git is in use. Only the synchonization
of bookmarks should be considered "under test", and mutation of bookmarks
locally is only to provide a test fixture.
Load commonly used test logic
$ . "$TESTDIR/testutil"
Skip if Mercurial < 2.1; workflow was different before that
$ python -c 'from mercurial import util ; assert \
> util.version() != "unknown" and util.version() >= "2.1"' || exit 80
$ gitcount=10
$ gitcommit()
> {
> GIT_AUTHOR_DATE="2007-01-01 00:00:$gitcount +0000"
> GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
> git commit "$@" >/dev/null 2>/dev/null || echo "git commit error"
> gitcount=`expr $gitcount + 1`
> }
$ hgcount=10
$ hgcommit()
> {
> HGDATE="2007-01-01 00:00:$hgcount +0000"
> hg commit -u "test <test@example.org>" -d "$HGDATE" "$@" >/dev/null 2>/dev/null || echo "hg commit error"
> hgcount=`expr $hgcount + 1`
> }
$ gitstate()
> {
> git log --format=" %h \"%s\" refs:%d" $@ | sed 's/HEAD, //'
> }
$ hgstate()
> {
> hg log --template " {rev} {node|short} \"{desc}\" bookmarks: [{bookmarks}]\n" $@
> }
$ hggitstate()
> {
> hg log --template " {rev} {node|short} {gitnode|short} \"{desc}\" bookmarks: [{bookmarks}]\n" $@
> }
Initialize remote hg and git repos with equivalent initial contents
$ hg init hgremoterepo
$ cd hgremoterepo
$ hg bookmark master
$ for f in alpha beta gamma delta; do
> echo $f > $f; hg add $f; hgcommit -m "add $f"
> done
$ hg bookmark -r 1 b1
$ hgstate
3 fc2664cac217 "add delta" bookmarks: [master]
2 d85ced7ae9d6 "add gamma" bookmarks: []
1 7bcd915dc873 "add beta" bookmarks: [b1]
0 3442585be8a6 "add alpha" bookmarks: []
$ cd ..
$ git init -q gitremoterepo
$ cd gitremoterepo
$ for f in alpha beta gamma delta; do
> echo $f > $f; git add $f; gitcommit -m "add $f"
> done
$ git branch b1 9497a4e
$ gitstate
55b133e "add delta" refs: (master)
d338971 "add gamma" refs:
9497a4e "add beta" refs: (b1)
7eeab2e "add alpha" refs:
$ cd ..
Cloning transfers all bookmarks from remote to local
$ hg clone -q hgremoterepo purehglocalrepo
$ cd purehglocalrepo
$ hgstate
3 fc2664cac217 "add delta" bookmarks: [master]
2 d85ced7ae9d6 "add gamma" bookmarks: []
1 7bcd915dc873 "add beta" bookmarks: [b1]
0 3442585be8a6 "add alpha" bookmarks: []
$ cd ..
$ hg clone -q gitremoterepo hggitlocalrepo
$ cd hggitlocalrepo
$ hggitstate
3 fc2664cac217 55b133e1d558 "add delta" bookmarks: [master]
2 d85ced7ae9d6 d338971a96e2 "add gamma" bookmarks: []
1 7bcd915dc873 9497a4ee62e1 "add beta" bookmarks: [b1]
0 3442585be8a6 7eeab2ea75ec "add alpha" bookmarks: []
$ cd ..
No changes
$ cd purehglocalrepo
$ hg outgoing
comparing with $TESTTMP/hgremoterepo
searching for changes
no changes found
[1]
$ hg outgoing -B
comparing with $TESTTMP/hgremoterepo
searching for changed bookmarks
no changed bookmarks found
[1]
$ hg push
pushing to $TESTTMP/hgremoterepo
searching for changes
no changes found
[1]
$ cd ..
$ cd hggitlocalrepo
$ hg outgoing
comparing with $TESTTMP/gitremoterepo
searching for changes
no changes found
[1]
$ hg outgoing -B
comparing with $TESTTMP/gitremoterepo
searching for changed bookmarks
no changed bookmarks found
[1]
$ hg push
pushing to $TESTTMP/gitremoterepo
searching for changes
no changes found
[1]
$ cd ..
Changed bookmarks, but not revs
$ cd purehglocalrepo
$ hg bookmark -fr 2 b1
$ hg bookmark -r 0 b2
$ hgstate
3 fc2664cac217 "add delta" bookmarks: [master]
2 d85ced7ae9d6 "add gamma" bookmarks: [b1]
1 7bcd915dc873 "add beta" bookmarks: []
0 3442585be8a6 "add alpha" bookmarks: [b2]
$ hg outgoing
comparing with $TESTTMP/hgremoterepo
searching for changes
no changes found
[1]
As of 2.3, Mercurial's outgoing -B doesn't actually show changed bookmarks
It only shows "new" bookmarks. Thus, b1 doesn't show up.
$ hg outgoing -B
comparing with $TESTTMP/hgremoterepo
searching for changed bookmarks
b2 3442585be8a6
$ cd ..
$ cd hggitlocalrepo
$ hg bookmark -fr 2 b1
$ hg bookmark -r 0 b2
$ hgstate
3 fc2664cac217 "add delta" bookmarks: [master]
2 d85ced7ae9d6 "add gamma" bookmarks: [b1]
1 7bcd915dc873 "add beta" bookmarks: []
0 3442585be8a6 "add alpha" bookmarks: [b2]
$ hg outgoing
comparing with $TESTTMP/gitremoterepo
searching for changes
no changes found
[1]
As of 2.3, Mercurial's outgoing -B doesn't actually show changed bookmarks
It only shows "new" bookmarks. Thus, b1 doesn't show up.
$ hg outgoing -B
comparing with $TESTTMP/gitremoterepo
searching for changed bookmarks
b2 3442585be8a6
$ cd ..