# HG changeset patch
# User David M. Carr <david@carrclan.us>
# Date 1351641806 14400
#      Tue Oct 30 20:03:26 2012 -0400
# Node ID a7da97e69d56a7edc284cd7cfe1f552c9288d45d
# Parent  d4ad5de012a0e56b7b9da47dccabdc589642e904
tests: extract extension configuration into a testutil library

Thanks to Felipe Contreras for the patch which this was based on.

Even though the MQ extension was only used in a single test
(test-pull-after-strip.t), I included it in the testutil.  It shouldn't hurt
anything to have it enabled and not used, and saves us from having to deal
with enabling extensions in individual tests at all.

Similarly, this changeset results in the graphlog extension being enabled
for all tests, even though there were some that didn't use it before.  This is
even less significant in Mercurial 2.3+, since in those versions, graphlog is
part of core, and is available even when the extension is disabled.

diff --git a/tests/test-bookmark-workflow.t b/tests/test-bookmark-workflow.t
--- a/tests/test-bookmark-workflow.t
+++ b/tests/test-bookmark-workflow.t
@@ -9,6 +9,9 @@
 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"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
@@ -19,9 +22,6 @@
   $ python -c 'from mercurial import util ; assert \
   >  util.version() != "unknown" and util.version() >= "2.1"' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $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
diff --git a/tests/test-clone.t b/tests/test-clone.t
--- a/tests/test-clone.t
+++ b/tests/test-clone.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $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
diff --git a/tests/test-conflict-1.t b/tests/test-conflict-1.t
--- a/tests/test-conflict-1.t
+++ b/tests/test-conflict-1.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $HGRCPATH
-
   $ hg init hgrepo1
   $ cd hgrepo1
   $ echo A > afile
diff --git a/tests/test-conflict-2.t b/tests/test-conflict-2.t
--- a/tests/test-conflict-2.t
+++ b/tests/test-conflict-2.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $HGRCPATH
-
   $ hg init hgrepo1
   $ cd hgrepo1
   $ echo A > afile
diff --git a/tests/test-convergedmerge.t b/tests/test-convergedmerge.t
--- a/tests/test-convergedmerge.t
+++ b/tests/test-convergedmerge.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $HGRCPATH
-
   $ hg init hgrepo1
   $ cd hgrepo1
   $ echo A > afile
diff --git a/tests/test-empty-working-tree.t b/tests/test-empty-working-tree.t
--- a/tests/test-empty-working-tree.t
+++ b/tests/test-empty-working-tree.t
@@ -1,12 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $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
diff --git a/tests/test-encoding.t b/tests/test-encoding.t
--- a/tests/test-encoding.t
+++ b/tests/test-encoding.t
@@ -1,15 +1,14 @@
 # -*- coding: utf-8 -*-
 
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $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
diff --git a/tests/test-file-removal.t b/tests/test-file-removal.t
--- a/tests/test-file-removal.t
+++ b/tests/test-file-removal.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $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
diff --git a/tests/test-git-clone.t b/tests/test-git-clone.t
--- a/tests/test-git-clone.t
+++ b/tests/test-git-clone.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $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
diff --git a/tests/test-git-submodules.t b/tests/test-git-submodules.t
--- a/tests/test-git-submodules.t
+++ b/tests/test-git-submodules.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $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
diff --git a/tests/test-git-tags.t b/tests/test-git-tags.t
--- a/tests/test-git-tags.t
+++ b/tests/test-git-tags.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $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
diff --git a/tests/test-git-workflow.t b/tests/test-git-workflow.t
--- a/tests/test-git-workflow.t
+++ b/tests/test-git-workflow.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $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
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -1,7 +1,7 @@
 Tests that the various help files are properly registered
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
 
   $ hg help | grep 'git' | sed 's/  */ /g'
    hggit push and pull from a Git server
diff --git a/tests/test-hg-author.t b/tests/test-hg-author.t
--- a/tests/test-hg-author.t
+++ b/tests/test-hg-author.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $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
diff --git a/tests/test-hg-branch.t b/tests/test-hg-branch.t
--- a/tests/test-hg-branch.t
+++ b/tests/test-hg-branch.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $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
diff --git a/tests/test-hg-tags.t b/tests/test-hg-tags.t
--- a/tests/test-hg-tags.t
+++ b/tests/test-hg-tags.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $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
diff --git a/tests/test-incoming.t b/tests/test-incoming.t
--- a/tests/test-incoming.t
+++ b/tests/test-incoming.t
@@ -1,3 +1,6 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
@@ -8,10 +11,6 @@
   $ python -c 'from mercurial import util ; assert \
   >  util.version() != "unknown" and util.version() > "1.7"' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $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
diff --git a/tests/test-keywords.t b/tests/test-keywords.t
--- a/tests/test-keywords.t
+++ b/tests/test-keywords.t
@@ -1,12 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $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
diff --git a/tests/test-merge.t b/tests/test-merge.t
--- a/tests/test-merge.t
+++ b/tests/test-merge.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $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
diff --git a/tests/test-octopus.t b/tests/test-octopus.t
--- a/tests/test-octopus.t
+++ b/tests/test-octopus.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $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
diff --git a/tests/test-outgoing.t b/tests/test-outgoing.t
--- a/tests/test-outgoing.t
+++ b/tests/test-outgoing.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $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
diff --git a/tests/test-pull-after-strip.t b/tests/test-pull-after-strip.t
--- a/tests/test-pull-after-strip.t
+++ b/tests/test-pull-after-strip.t
@@ -1,3 +1,6 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
@@ -15,13 +18,6 @@
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ cat >> $HGRCPATH <<EOF
-  > [extensions]
-  > graphlog=
-  > mq=
-  > EOF
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $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
diff --git a/tests/test-pull.t b/tests/test-pull.t
--- a/tests/test-pull.t
+++ b/tests/test-pull.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $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
diff --git a/tests/test-push-r.t b/tests/test-push-r.t
--- a/tests/test-push-r.t
+++ b/tests/test-push-r.t
@@ -1,10 +1,9 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $HGRCPATH
-
   $ hg init test
   $ cd test
   $ cat >>afile <<EOF
diff --git a/tests/test-push.t b/tests/test-push.t
--- a/tests/test-push.t
+++ b/tests/test-push.t
@@ -1,13 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
-  $ echo 'hgext.graphlog =' >> $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
diff --git a/tests/test-subrepos.t b/tests/test-subrepos.t
--- a/tests/test-subrepos.t
+++ b/tests/test-subrepos.t
@@ -1,12 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $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
diff --git a/tests/test-tree-decomposition.t b/tests/test-tree-decomposition.t
--- a/tests/test-tree-decomposition.t
+++ b/tests/test-tree-decomposition.t
@@ -1,12 +1,12 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
 bail if the user does not have git command-line client
   $ "$TESTDIR/hghave" git || exit 80
 
 bail if the user does not have dulwich
   $ python -c 'import dulwich, dulwich.repo' || exit 80
 
-  $ echo "[extensions]" >> $HGRCPATH
-  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $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
diff --git a/tests/testutil b/tests/testutil
new file mode 100755
--- /dev/null
+++ b/tests/testutil
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+# This file holds logic that is used in many tests.
+# It can be called in a test like this:
+#  $ . "$TESTDIR/testutil"
+
+# Activate extensions
+echo "[extensions]" >> $HGRCPATH
+echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
+# Not needed in Mercurial 2.3+, as graphlog was integrated into core
+echo 'graphlog=' >> $HGRCPATH
+echo 'mq=' >> $HGRCPATH