[PATCH 1 of 8 hglib] client: add add command

Idan Kamara idankk86 at gmail.com
Sat Aug 13 16:58:32 CDT 2011


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1313272099 -10800
# Node ID 3d55991619d558dc5beba91d8c7c5f4fb3def647
# Parent  39cf14a0934225938ff10b0e655bd93872ef6ff3
client: add add command

diff -r 39cf14a09342 -r 3d55991619d5 hglib/client.py
--- 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:


More information about the Mercurial-devel mailing list