Ludovic Chabant avatar Ludovic Chabant committed d920e34

Added parameter to filter the type of subrepo to loop through.
Added tests.

Comments (0)

Files changed (3)

     precmd = None
     postcmd = None
     includeroot = opts.get('root_repo')
+    repotypefilter = opts.get('type')
 
     def execCmd(sub, cmd, kind):
         """if sub == None, cmd is executed inside repo; else, inside sub.
                               HG_REPO=repo.root,
                               HG_SUBTYPE=kind)
             cmdwd = os.path.join(repo.root, relpath)
-        if cmd != None:
+        if cmd != None and (repotypefilter == '' or repotypefilter == kind):
             if print0:
                 ui.write(relpath, "\0")
             if cmd != '':
            _('limit recursion to N levels (negative for no limit)'), 'N'),
           ('', 'ignore-errors', None,
            _('continue execution despite errors')),
+          ('t', 'type', '',
+           _('the type of repo to filter'), 'TYPE'),
           ('0', 'print0', None,
            _('end subrepository names with NUL, for use with xargs'))],
-         _('[-b] [-0] [--ignore-errors] CMD [POST-CMD]'))
+         _('[-b] [-0] [-t TYPE] [--ignore-errors] CMD [POST-CMD]'))
 }

test-onsub-mixed.t

   b = hg
   git-i = git
 
+Test the type filter
+
+  $ hg onsub 'echo $HG_SUBPATH' -t hg
+  a
+  b
+
+  $ hg onsub 'echo $HG_SUBPATH' -t git
+  a/git-j
+  git-i
+
+Test the type filter including the root repository
+
+  $ hg onsub 'echo $HG_SUBPATH' -t hg --root-repo
+  .
+  a
+  b
+
+  $ hg onsub 'echo $HG_SUBPATH' -t git --root-repo
+  a/git-j
+  git-i
+
 Check help formatting:
 
   $ hg help onsub
-  hg onsub [-b] [-0] [--ignore-errors] CMD [POST-CMD]
+  hg onsub [-b] [-0] [-t TYPE] [--ignore-errors] CMD [POST-CMD]
   
   execute a command in each subrepository
   
       --max-depth N   limit recursion to N levels (negative for no limit)
                       (default: -1)
       --ignore-errors continue execution despite errors
+   -t --type TYPE     the type of repo to filter
    -0 --print0        end subrepository names with NUL, for use with xargs
   
   use "hg -v help onsub" to show more info
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.