##// END OF EJS Templates
run commit and update hooks after command completion (issue1827)...
Sune Foldager -
r10492:0e64d814 stable
parent child Browse files
Show More
@@ -480,7 +480,14 b' def reposetup(ui, repo):'
480 # other extensions can still wrap repo.commitctx directly
480 # other extensions can still wrap repo.commitctx directly
481 self.commitctx = self.kwcommitctx
481 self.commitctx = self.kwcommitctx
482 try:
482 try:
483 return super(kwrepo, self).commit(*args, **opts)
483 self._kwcommithooks = {}
484 n = super(kwrepo, self).commit(*args, **opts)
485 if self._kwcommithooks:
486 xp1, xp2 = self._kwxp1, self._kwxp2
487 for name, cmd in self._kwcommithooks.iteritems():
488 ui.setconfig('hooks', name, cmd)
489 self.hook('commit', node=n, parent1=xp1, parent2=xp2)
490 return n
484 finally:
491 finally:
485 del self.commitctx
492 del self.commitctx
486
493
@@ -490,23 +497,18 b' def reposetup(ui, repo):'
490 wlock = self.wlock()
497 wlock = self.wlock()
491 lock = self.lock()
498 lock = self.lock()
492 # store and postpone commit hooks
499 # store and postpone commit hooks
493 commithooks = {}
494 for name, cmd in ui.configitems('hooks'):
500 for name, cmd in ui.configitems('hooks'):
495 if name.split('.', 1)[0] == 'commit':
501 if name.split('.', 1)[0] == 'commit':
496 commithooks[name] = cmd
502 self._kwcommithooks[name] = cmd
497 ui.setconfig('hooks', name, None)
503 ui.setconfig('hooks', name, None)
498 if commithooks:
504 if self._kwcommithooks:
499 # store parents for commit hooks
505 # store parents for commit hooks
500 p1, p2 = ctx.p1(), ctx.p2()
506 p1, p2 = ctx.p1(), ctx.p2()
501 xp1, xp2 = p1.hex(), p2 and p2.hex() or ''
507 self._kwxp1, self._kwxp2 = p1.hex(), p2 and p2.hex() or ''
502
508
503 n = super(kwrepo, self).commitctx(ctx, error)
509 n = super(kwrepo, self).commitctx(ctx, error)
504
510
505 kwt.overwrite(n, True, None)
511 kwt.overwrite(n, True, None)
506 if commithooks:
507 for name, cmd in commithooks.iteritems():
508 ui.setconfig('hooks', name, cmd)
509 self.hook('commit', node=n, parent1=xp1, parent2=xp2)
510 return n
512 return n
511 finally:
513 finally:
512 release(lock, wlock)
514 release(lock, wlock)
@@ -846,6 +846,8 b' class localrepository(repo.repository):'
846 msgfile.close()
846 msgfile.close()
847
847
848 try:
848 try:
849 hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '')
850 self.hook("precommit", throw=True, parent1=hookp1, parent2=hookp2)
849 ret = self.commitctx(cctx, True)
851 ret = self.commitctx(cctx, True)
850 except:
852 except:
851 if edited:
853 if edited:
@@ -861,15 +863,14 b' class localrepository(repo.repository):'
861 self.dirstate.forget(f)
863 self.dirstate.forget(f)
862 self.dirstate.setparents(ret)
864 self.dirstate.setparents(ret)
863 ms.reset()
865 ms.reset()
864
865 return ret
866
867 finally:
866 finally:
868 wlock.release()
867 wlock.release()
869
868
869 self.hook("commit", node=hex(ret), parent1=hookp1, parent2=hookp2)
870 return ret
871
870 def commitctx(self, ctx, error=False):
872 def commitctx(self, ctx, error=False):
871 """Add a new revision to current repository.
873 """Add a new revision to current repository.
872
873 Revision information is passed via the context argument.
874 Revision information is passed via the context argument.
874 """
875 """
875
876
@@ -880,9 +881,6 b' class localrepository(repo.repository):'
880 m2 = p2.manifest()
881 m2 = p2.manifest()
881 user = ctx.user()
882 user = ctx.user()
882
883
883 xp1, xp2 = p1.hex(), p2 and p2.hex() or ''
884 self.hook("precommit", throw=True, parent1=xp1, parent2=xp2)
885
886 lock = self.lock()
884 lock = self.lock()
887 try:
885 try:
888 tr = self.transaction()
886 tr = self.transaction()
@@ -925,6 +923,7 b' class localrepository(repo.repository):'
925 trp, p1.node(), p2.node(),
923 trp, p1.node(), p2.node(),
926 user, ctx.date(), ctx.extra().copy())
924 user, ctx.date(), ctx.extra().copy())
927 p = lambda: self.changelog.writepending() and self.root or ""
925 p = lambda: self.changelog.writepending() and self.root or ""
926 xp1, xp2 = p1.hex(), p2 and p2.hex() or ''
928 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
927 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
929 parent2=xp2, pending=p)
928 parent2=xp2, pending=p)
930 self.changelog.finalize(trp)
929 self.changelog.finalize(trp)
@@ -932,8 +931,6 b' class localrepository(repo.repository):'
932
931
933 if self._branchcache:
932 if self._branchcache:
934 self.branchtags()
933 self.branchtags()
935
936 self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2)
937 return n
934 return n
938 finally:
935 finally:
939 del tr
936 del tr
@@ -511,8 +511,9 b' def update(repo, node, branchmerge, forc'
511 repo.dirstate.setparents(fp1, fp2)
511 repo.dirstate.setparents(fp1, fp2)
512 if not branchmerge and not fastforward:
512 if not branchmerge and not fastforward:
513 repo.dirstate.setbranch(p2.branch())
513 repo.dirstate.setbranch(p2.branch())
514 repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3])
515
516 return stats
517 finally:
514 finally:
518 wlock.release()
515 wlock.release()
516
517 if not partial:
518 repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3])
519 return stats
@@ -205,8 +205,8 b" echo '# make sure --traceback works'"
205 echo '[hooks]' > .hg/hgrc
205 echo '[hooks]' > .hg/hgrc
206 echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc
206 echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc
207
207
208 echo a >> a
208 echo aa > a
209 hg --traceback commit -A -m a 2>&1 | grep '^Traceback'
209 hg --traceback commit -d '0 0' -ma 2>&1 | grep '^Traceback'
210
210
211 cd ..
211 cd ..
212 hg init c
212 hg init c
@@ -224,9 +224,9 b" echo 'hookext = hookext.py' >> .hg/hgrc"
224
224
225 touch foo
225 touch foo
226 hg add foo
226 hg add foo
227 hg ci -m 'add foo'
227 hg ci -d '0 0' -m 'add foo'
228 echo >> foo
228 echo >> foo
229 hg ci --debug -m 'change foo' | sed -e 's/ at .*>/>/'
229 hg ci --debug -d '0 0' -m 'change foo' | sed -e 's/ at .*>/>/'
230
230
231 hg showconfig hooks | sed -e 's/ at .*>/>/'
231 hg showconfig hooks | sed -e 's/ at .*>/>/'
232
232
@@ -246,7 +246,7 b" echo '[hooks]' > ../repo/.hg/hgrc"
246 echo "pre-commit.test = python:`pwd`/testhooks.py:testhook" >> ../repo/.hg/hgrc
246 echo "pre-commit.test = python:`pwd`/testhooks.py:testhook" >> ../repo/.hg/hgrc
247
247
248 cd ../repo
248 cd ../repo
249 hg commit
249 hg commit -d '0 0'
250
250
251 cd ../../b
251 cd ../../b
252 echo '# make sure --traceback works on hook import failure'
252 echo '# make sure --traceback works on hook import failure'
@@ -260,6 +260,14 b" echo '[hooks]' > .hg/hgrc"
260 echo 'precommit.importfail = python:importfail.whatever' >> .hg/hgrc
260 echo 'precommit.importfail = python:importfail.whatever' >> .hg/hgrc
261
261
262 echo a >> a
262 echo a >> a
263 hg --traceback commit -Ama 2>&1 | egrep '^(exception|Traceback|ImportError)'
263 hg --traceback commit -d '0 0' -ma 2>&1 | egrep '^(exception|Traceback|ImportError)'
264
265 echo '# commit and update hooks should run after command completion (issue 1827)'
266 echo '[hooks]' > .hg/hgrc
267 echo 'commit = hg id' >> .hg/hgrc
268 echo 'update = hg id' >> .hg/hgrc
269 echo bb > a
270 hg ci -d '0 0' -ma
271 hg up 0
264
272
265 exit 0
273 exit 0
@@ -171,3 +171,7 b' exception from second failed import atte'
171 Traceback (most recent call last):
171 Traceback (most recent call last):
172 ImportError: No module named hgext_importfail
172 ImportError: No module named hgext_importfail
173 Traceback (most recent call last):
173 Traceback (most recent call last):
174 # commit and update hooks should run after command completion (issue 1827)
175 8da618c33484 tip
176 29b62aeb769f
177 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
General Comments 0
You need to be logged in to leave comments. Login now