Reparse cmdline to avoid expansion in uncommitted files updatehook
authorChristian Ebert <blacktrash@gmx.net>
Sun, 17 Dec 2006 13:38:28 +0100
branchupdatehook
changeset 26 bda0dec1aaf1
parent 25 aa3fbe81e9ad
child 27 d00d45c7ddaf
Reparse cmdline to avoid expansion in uncommitted files
hgkw/pretxnkw.py
--- a/hgkw/pretxnkw.py	Sun Dec 17 10:57:55 2006 +0100
+++ b/hgkw/pretxnkw.py	Sun Dec 17 13:38:28 2006 +0100
@@ -1,6 +1,8 @@
 # $Hg$
 
 import kwexpander
+from mercurial import cmdutil, commands
+import sys
 
 def pretxnkw(ui, repo, hooktype, **args):
     '''Important: returns False on success, True on failure.'''
@@ -9,10 +11,18 @@
         # bail out with error
         return True
 
-    tip = repo.changelog.tip()
-    modified, added = repo.status()[:2]
+    # reparse args, opts again as pretxncommit hook is silent about them
+    sysargs, globalopts, cmdopts = commands.parse(ui, sys.argv[1:])[2:]
+    files, match, anypats = cmdutil.matchpats(repo, sysargs, cmdopts)
+
+    # validity checks should have been done already
+    modified, added = repo.status(files=files, match=match)[:2]
     candidates = modified + added
-    # TODO: check whether we need parent1&2 like in updatekw
 
-    return kwexpander.expandkw(ui, repo,
-            tip, args['node'][0:12], candidates, update=False)
+    if candidates:
+        r = repo.changelog.tip()
+        n = args['node'][:12]
+        # TODO: check whether we need parent1&2 like in updatekw
+        return kwexpander.expandkw(ui, repo, r, n, candidates, update=False)
+
+    return False