changeset 288:0080dab59fac

Begin tests with subrepos and some preparations for nested subrepos
author Franz Glasner <hg@dom66.de>
date Thu, 17 Jan 2019 09:38:19 +0100
parents 95c207d21bbf
children 986d1472580c
files extensions/kwarchive.py tests/lib-test-kwarchive.sh tests/test-kwarchive.t
diffstat 3 files changed, 198 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/extensions/kwarchive.py	Wed Jan 16 21:18:49 2019 +0100
+++ b/extensions/kwarchive.py	Thu Jan 17 09:38:19 2019 +0100
@@ -87,7 +87,7 @@
 import inspect
 
 from mercurial.i18n import _
-from mercurial import (archival, config, cmdutil, error, match,
+from mercurial import (archival, config, cmdutil, error, match, subrepo,
                        pycompat, scmutil, templatefilters, util, node)
 try:
     from mercurial import registrar
@@ -367,6 +367,11 @@
                 ui.write(".. |VCS%s| replace:: %s\n" % (key, file_keywords[key]))
             else:
                 ui.write("$%s: %s $\n" % (key, file_keywords[key]))
+    if opts.get("subrepos"):
+        for subpath in sorted(ctx.substate):
+            ui.write("SUBPATH: " + subpath + "\n");
+            subrep = ctx.workingsub(subpath)
+            ui.write(repr(subrep) + " " + subrepo.subrelpath(subrep) + '\n');
 
 
 def patch_archiver_class(archivername, filter):
--- a/tests/lib-test-kwarchive.sh	Wed Jan 16 21:18:49 2019 +0100
+++ b/tests/lib-test-kwarchive.sh	Thu Jan 17 09:38:19 2019 +0100
@@ -141,3 +141,124 @@
 
     cd ..
 }
+
+
+#
+# Prepare a sub-repository within the current repository
+#
+# prepare_subrepo SUBREPO SUBDIR
+#
+prepare_subrepo() {
+    if [ ! -z "$2" ]; then
+	mkdir "$2"
+	cd "$2"
+    fi
+    mkdir "$1"
+    cd "$1"
+    hg init
+    # configure the very same patterns here as in the parent repo
+    # just to show that they are without any effects
+    cat >.hgkwarchive <<EOF
+[patterns]
+src/**.py = RCS, reST
+path:VERSION = reST
+path:README = RCS, reST
+path:test2.txt = RCS, reST
+
+[keywords]
+JustDate =
+HGheader =
+HGnodeid =
+Date =
+Revision =
+HGrevision =
+Author =
+
+MyFullRevision = HGrevision
+
+MySubstKeyword = replace:: This is a custom replacement
+EOF    
+    cat >f1.txt <<EOF
+f1.txt: Some file content
+EOF
+    hg add .hgkwarchive
+    hg commit -m '1: locally activate kwarchive'
+
+    cat >>VERSION <<\EOF
+0.0.dev1
+|VCSMyFullRevision|
+EOF
+    cat >>README <<\EOF
+.. -*- coding: utf-8 -*-
+
+Testing the kwarchive extension in a subrepo
+============================================
+
+:Author:  Franz Glasner
+:When:    $Date$
+:Date:    |VCSJustDate|
+:ID:      @(#) $HGheader$
+
+EOF
+    cat >>test2.txt <<\EOF
+test2.txt: This is a file with some replacement tests
+
+$HGheader$
+$HGnodeid$
+$Date$
+$JustDate$
+$HGrevision$
+$Revision$
+$Author$
+
+$MySubstKeyword$
+|VCSMySubstKeyword|
+EOF
+    # not to be expanded
+    cp test2.txt test2-not-expanded.txt
+    mkdir src
+    cat >>src/f1.py <<\EOF
+# -*- coding: utf-8 -*-
+# src/f1.py
+# @(#) $HGheader$
+# $HGnodeid$
+#
+__revision__ = "$Revision$"
+__author__ = "Franz Glasner"
+
+EOF
+    cp src/f1.py src/f1.txt
+    cat >>src/f2.py <<\EOF
+# -*- coding: utf-8 -*-
+# src/f2.py
+# @(#) $HGheader$
+# $HGnodeid$
+#
+__revision__ = "$Revision$"
+__author__ = "Franz Glasner"
+
+EOF
+    cp src/f2.py src/f2.txt
+    hg add VERSION README test2.txt test2-not-expanded.txt
+    hg commit -m '2: First part of files: VERSION, README, test2.txt'
+    hg add --quiet src/
+    hg ci -m '3: All files in src'
+    # should have no output
+    hg st
+    if [ ! -z "$2" ]; then
+	cd ..
+    fi    
+    cd ..
+    # and really add/activate the subrepo in the parent
+    if [ ! -z "$2" ]; then
+	cat >.hgsub <<EOF
+$2/$1 = file:///$1
+EOF
+    else
+	cat >.hgsub <<EOF
+$1 = $1
+EOF
+    fi
+    hg add .hgsub
+    hg commit -m "Add subrepo $1"
+}
--- a/tests/test-kwarchive.t	Wed Jan 16 21:18:49 2019 +0100
+++ b/tests/test-kwarchive.t	Thu Jan 17 09:38:19 2019 +0100
@@ -269,3 +269,74 @@
   __revision__ = "$Revision: 8c27876b7952 $"
   __author__ = "Franz Glasner"
    (?)
+
+  $ cd ..
+
+Archiving with subrepos
+
+  $ prepare_repo "repo2"
+  $ cd "repo2"
+  $ prepare_subrepo "subrepo1"
+  $ echo `pwd`
+  $TESTTMP/repo2
+  $ cat .hgsubstate
+  ^[a-f0-9]+\s+subrepo1$ (re)
+
+... archiving subrepos does not automatically anything expand in the subrepos
+
+  $ hg kwarchive -S --path-filter=full --user-filter=full _archive
+  $ cat _archive/subrepo1/test2.txt
+  test2.txt: This is a file with some replacement tests
+  ^$ (re)
+  $HGheader$
+  $HGnodeid$
+  $Date$
+  $JustDate$
+  $HGrevision$
+  $Revision$
+  $Author$
+  ^$ (re)
+  $MySubstKeyword$
+  |VCSMySubstKeyword|
+
+... but simple configuring it in the parent within the "patterns" yields
+... an error
+
+  $ cat >.hgkwarchive <<EOF
+  > [patterns]
+  > subrepo1/** = RCS, reST
+  > src/**.py = RCS, reST
+  > path:VERSION = reST
+  > path:README = RCS, reST
+  > path:test2.txt = RCS, reST
+  > subrepo1/** = RCS, reST
+  > 
+  > [keywords]
+  > JustDate =
+  > HGheader =
+  > HGnodeid =
+  > Date =
+  > Revision =
+  > HGrevision =
+  > Author =
+  > 
+  > MyFullRevision = HGrevision
+  > 
+  > MySubstKeyword = replace:: This is a custom replacement
+  > EOF
+  $ hg commit -m "New kwarchive configuration"
+  $ hg kwarchive -S --path-filter=full --user-filter=full _archive2
+  abort: path 'subrepo1/**' is inside nested repo 'subrepo1'
+  [255]
+
+  $ cd ..
+
+Archiving with nested subrepos
+
+  $ prepare_repo "repo3"
+  $ cd "repo3"
+  $ prepare_subrepo "subrepo1" "subrepos"
+  $ echo `pwd`
+  $TESTTMP/repo3
+  $ cat .hgsubstate
+  ^[a-f0-9]+\s+subrepos/subrepo1$ (re)