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