[PATCH] subrepos: support adding files in git subrepos
Mathias De Maré
mathias.demare at gmail.com
Tue Feb 24 07:49:49 UTC 2015
# HG changeset patch
# User Mathias De Maré <mathias.demare at gmail.com>
# Date 1424764162 -3600
# Tue Feb 24 08:49:22 2015 +0100
# Node ID 391c33821c0399e40979ef2440289844f8e12756
# Parent ff5caa8dfd993680d9602ca6ebb14da9de10d5f4
subrepos: support adding files in git subrepos
This support includes correct matching, so includes,
excludes and patterns are all supported.
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -1524,6 +1524,24 @@
return False
@annotatesubrepoerror
+ def add(self, ui, match, prefix, explicitonly, **opts):
+ rev = self._state[1]
+ if match.files():
+ files = match.files()
+ elif match.always():
+ self._gitcommand(["add", "--all"])
+ return []
+ else:
+ (modified, added, removed,
+ deleted, unknown, ignored, clean) = self.status(None)
+ files = unknown
+ if match:
+ files = [f for f in files if match(f)]
+ for f in files:
+ self._gitcommand(["add", f])
+ return []
+
+ @annotatesubrepoerror
def remove(self):
if self._gitmissing():
return
diff --git a/tests/test-subrepo-git.t b/tests/test-subrepo-git.t
--- a/tests/test-subrepo-git.t
+++ b/tests/test-subrepo-git.t
@@ -850,4 +850,59 @@
$ hg cat -r "parents(.)" --output tmp/%b/foobar s/foobar
$ diff tmp/tc/foobar catparents
+cleanup
+ $ rm -r tmp
+ $ rm catparents
+
+add git files, using either files or patterns
+ $ echo "hsss! hsssssssh!" > s/snake.python
+ $ echo "ccc" > s/c.c
+ $ echo "cpp" > s/cpp.cpp
+
+ $ hg add s/snake.python s/c.c s/cpp.cpp
+ $ hg st --subrepos s
+ M s/foobar
+ A s/c.c
+ A s/cpp.cpp
+ A s/snake.python
+ ? s/barfoo
+ $ hg revert s
+ reverting subrepo ../gitroot
+
+ $ hg add --subrepos "glob:**.python"
+ $ hg st --subrepos s
+ A s/snake.python
+ ? s/barfoo
+ ? s/c.c
+ ? s/cpp.cpp
+ ? s/foobar.orig
+ $ hg revert s
+ reverting subrepo ../gitroot
+
+ $ hg add --subrepos s
+ $ hg st --subrepos s
+ A s/barfoo
+ A s/c.c
+ A s/cpp.cpp
+ A s/foobar.orig
+ A s/snake.python
+ $ hg revert s
+ reverting subrepo ../gitroot
+make sure everything is reverted correctly
+ $ hg st --subrepos s
+ ? s/barfoo
+ ? s/c.c
+ ? s/cpp.cpp
+ ? s/foobar.orig
+ ? s/snake.python
+
+ $ hg add --subrepos --exclude "path:s/c.c"
+ $ hg st --subrepos s
+ A s/barfoo
+ A s/cpp.cpp
+ A s/foobar.orig
+ A s/snake.python
+ ? s/c.c
+ $ hg revert --all -q
+
$ cd ..
More information about the Mercurial-devel
mailing list