changeset 28:221eeb3693f4

client: add add command
author Idan Kamara <idankk86@gmail.com>
date Sun, 14 Aug 2011 00:48:19 +0300
parents 46908f4b87d5
children c072f525ea3e
files hglib/client.py
diffstat 1 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hglib/client.py	Thu Aug 11 22:59:05 2011 +0300
+++ b/hglib/client.py	Sun Aug 14 00:48:19 2011 +0300
@@ -140,6 +140,31 @@
         self.server = None
         return ret
 
+    def add(self, files=[], dryrun=False, subrepos=False, include=None,
+            exclude=None):
+        """
+        Add the specified files on the next commit.
+        If no files are given, add all files to the repository.
+
+        Return whether all given files were added.
+        """
+        if not isinstance(files, list):
+            files = [files]
+
+        args = cmdbuilder('add', *files, n=dryrun, S=subrepos, I=include, X=exclude)
+
+        # we could use Python 3 nonlocal here...
+        warnings = [False]
+
+        def eh(ret, out, err):
+            if ret == 1:
+                warnings[0] = True
+            else:
+                raise error.CommandError(args, ret, out, err)
+
+        self.rawcommand(args, eh=eh)
+        return not warnings[0]
+
     def backout(self, rev, merge=False, parent=None, tool=None, message=None,
                 logfile=None, date=None, user=None):
         if message and logfile: