Show More
@@ -48,7 +48,7 b' class localrepository(object):' | |||
|
48 | 48 | except IOError: |
|
49 | 49 | pass |
|
50 | 50 | |
|
51 | def hook(self, name, **args): | |
|
51 | def hook(self, name, throw=False, **args): | |
|
52 | 52 | def runhook(name, cmd): |
|
53 | 53 | self.ui.note(_("running hook %s: %s\n") % (name, cmd)) |
|
54 | 54 | old = {} |
@@ -57,21 +57,25 b' class localrepository(object):' | |||
|
57 | 57 | old[k] = os.environ.get(k, None) |
|
58 | 58 | os.environ[k] = v |
|
59 | 59 | |
|
60 | try: | |
|
60 | 61 | # Hooks run in the repository root |
|
61 | 62 | olddir = os.getcwd() |
|
62 | 63 | os.chdir(self.root) |
|
63 | 64 | r = os.system(cmd) |
|
64 | os.chdir(olddir) | |
|
65 | ||
|
65 | finally: | |
|
66 | 66 | for k, v in old.items(): |
|
67 | 67 | if v != None: |
|
68 | 68 | os.environ[k] = v |
|
69 | 69 | else: |
|
70 | 70 | del os.environ[k] |
|
71 | 71 | |
|
72 | os.chdir(olddir) | |
|
73 | ||
|
72 | 74 | if r: |
|
73 | self.ui.warn(_("abort: %s hook failed with status %d!\n") % | |
|
74 | (name, r)) | |
|
75 | desc, r = util.explain_exit(r) | |
|
76 | if throw: | |
|
77 | raise util.Abort(_('%s hook %s') % (name, desc)) | |
|
78 | self.ui.warn(_('error: %s hook %s\n') % (name, desc)) | |
|
75 | 79 | return False |
|
76 | 80 | return True |
|
77 | 81 | |
@@ -372,8 +376,7 b' class localrepository(object):' | |||
|
372 | 376 | self.ui.status(_("nothing changed\n")) |
|
373 | 377 | return None |
|
374 | 378 | |
|
375 |
|
|
|
376 | return None | |
|
379 | self.hook("precommit", throw=True) | |
|
377 | 380 | |
|
378 | 381 | if not wlock: |
|
379 | 382 | wlock = self.wlock() |
General Comments 0
You need to be logged in to leave comments.
Login now