Commits

Katsunori FUJIWARA committed 2e081fb

add initial contents

  • Participants

Comments (0)

Files changed (3)

+syntax: glob
+
+*~
+*.pyc
+======================================================================
+ addguard extension -- guard from careless adding all untracked files
+======================================================================
+
+This extension guards you from careless adding all untracked files.
+
+--------------------
+ Enabling extension
+--------------------
+
+Download source archive, extract it, and add configuration for extension::
+
+    [extensions]
+    addguard = /path/to/addguard.py
+
+Then, you can see detail about exdateformat extension by ``hg help
+addguard``.
+# addguard.py -- guard from careless adding all untracked files
+#
+# Copyright (c) 2012 FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+'''guard from careless adding all untracked files
+
+You can invoke :hg:`add` without any patterns, and it causes
+all untracked files to be added into tracking targets.
+
+This extension can guard you from such situation.
+
+You can choose type of guard by ``addguard`` section in configuration
+file::
+
+    [addguard]
+    # require '--all' option to add all untracked files (default).
+    # not only file patterns but also '-I'/'-X' options avoid guard.
+    type = allopt
+    # confirmt interactively.
+    # this also aborts, if executed not interactively.
+    type = prompt
+
+Even when ``prompt`` is chosen as guard type, ``--all`` option is effective.
+'''
+
+from mercurial.i18n import _
+from mercurial import util, extensions, commands
+
+def add(orgfunc, ui, repo, *pats, **opts):
+    if (not (pats or opts.get('include') or opts.get('exclude')) and
+        not opts.get('all')):
+        hint = _('see "hg help addguard" for detail')
+        type = ui.config('addguard', 'type', 'allopt')
+        if type == 'allopt':
+            raise util.Abort(_('Specify --all explicitly, '
+                               'if you want to add all untracked files'),
+                             hint=hint)
+        elif type == 'prompt':
+            if ui.interactive():
+                query = _('do you really want to add all untracked files'
+                          ' [yN]')
+                choices = (_('&Yes, add all untracked files'),
+                           _('&No, abort "hg add"'))
+                if ui.promptchoice(query, choices, 1) == 1:
+                    raise util.Abort(_('"hg add" is aborted interactively'),
+                                     hint=hint)
+            else:
+                raise util.Abort(_('non-interactive adding all untracked files'
+                                   ' is suppressed'),
+                                 hint=hint)
+        else:
+            raise util.Abort(_('unknonw addguard type: %s') % type,
+                             hint=hint)
+
+    return orgfunc(ui, repo, *pats, **opts)
+
+def uisetup(ui):
+    entry = extensions.wrapcommand(commands.table, 'add', add)
+    entry[1].append(('', 'all', None,
+                     _('allow to add all untracked files, '
+                       'when no arguments given')))