Show More
@@ -988,6 +988,20 b' be ``$HG_HOOKTYPE=incoming`` and ``$HG_H' | |||||
988 | phase changes will set ``HG_BOOKMARK_MOVED`` and ``HG_PHASES_MOVED`` to ``1`` |
|
988 | phase changes will set ``HG_BOOKMARK_MOVED`` and ``HG_PHASES_MOVED`` to ``1`` | |
989 | respectively, etc. |
|
989 | respectively, etc. | |
990 |
|
990 | |||
|
991 | ``pretxnclose-bookmark`` | |||
|
992 | Run right before a bookmark change is actually finalized. Any repository | |||
|
993 | change will be visible to the hook program. This lets you validate the | |||
|
994 | transaction content or change it. Exit status 0 allows the commit to | |||
|
995 | proceed. A non-zero status will cause the transaction to be rolled back. | |||
|
996 | The name of the bookmark will be available in ``$HG_BOOKMARK``, the new | |||
|
997 | bookmark location will be available in ``$HG_NODE`` while the previous | |||
|
998 | location will be available in ``$HG_OLDNODE``. In case of a bookmark | |||
|
999 | creation ``$HG_OLDNODE`` will be empty. In case of deletion ``$HG_NODE`` | |||
|
1000 | will be empty. | |||
|
1001 | In addition, the reason for the transaction opening will be in | |||
|
1002 | ``$HG_TXNNAME``, and a unique identifier for the transaction will be in | |||
|
1003 | ``HG_TXNID``. | |||
|
1004 | ||||
991 | ``txnclose`` |
|
1005 | ``txnclose`` | |
992 | Run after any repository transaction has been committed. At this |
|
1006 | Run after any repository transaction has been committed. At this | |
993 | point, the transaction can no longer be rolled back. The hook will run |
|
1007 | point, the transaction can no longer be rolled back. The hook will run | |
@@ -997,14 +1011,8 b' be ``$HG_HOOKTYPE=incoming`` and ``$HG_H' | |||||
997 | ``txnclose-bookmark`` |
|
1011 | ``txnclose-bookmark`` | |
998 | Run after any bookmark change has been committed. At this point, the |
|
1012 | Run after any bookmark change has been committed. At this point, the | |
999 | transaction can no longer be rolled back. The hook will run after the lock |
|
1013 | transaction can no longer be rolled back. The hook will run after the lock | |
1000 | is released. |
|
1014 | is released. See :hg:`help config.hooks.pretxnclose-bookmark` for details | |
1001 | The name of the bookmark will be available in ``$HG_BOOKMARK``, the new |
|
1015 | about available variables. | |
1002 | bookmark location will be available in ``$HG_NODE`` while the previous |
|
|||
1003 | location will be available in ``$HG_OLDNODE``. In case of a bookmark |
|
|||
1004 | creation ``$HG_OLDNODE`` will be empty. In case of deletion ``$HG_NODE`` |
|
|||
1005 | will be empty. In addition, the reason for the transaction opening will be |
|
|||
1006 | in ``$HG_TXNNAME``, and a unique identifier for the transaction will be in |
|
|||
1007 | ``HG_TXNID``. |
|
|||
1008 |
|
1016 | |||
1009 | ``txnabort`` |
|
1017 | ``txnabort`` | |
1010 | Run when a transaction is aborted. See :hg:`help config.hooks.pretxnclose` |
|
1018 | Run when a transaction is aborted. See :hg:`help config.hooks.pretxnclose` |
@@ -1235,8 +1235,17 b' class localrepository(object):' | |||||
1235 | # This will have to be fixed before we remove the experimental |
|
1235 | # This will have to be fixed before we remove the experimental | |
1236 | # gating. |
|
1236 | # gating. | |
1237 | tracktags(tr2) |
|
1237 | tracktags(tr2) | |
1238 | reporef().hook('pretxnclose', throw=True, |
|
1238 | repo = reporef() | |
1239 | txnname=desc, **pycompat.strkwargs(tr.hookargs)) |
|
1239 | if hook.hashook(repo.ui, 'pretxnclose-bookmark'): | |
|
1240 | for name, (old, new) in sorted(tr.changes['bookmarks'].items()): | |||
|
1241 | args = tr.hookargs.copy() | |||
|
1242 | args.update(bookmarks.preparehookargs(name, old, new)) | |||
|
1243 | repo.hook('pretxnclose-bookmark', throw=True, | |||
|
1244 | txnname=desc, | |||
|
1245 | **pycompat.strkwargs(args)) | |||
|
1246 | ||||
|
1247 | repo.hook('pretxnclose', throw=True, | |||
|
1248 | txnname=desc, **pycompat.strkwargs(tr.hookargs)) | |||
1240 | def releasefn(tr, success): |
|
1249 | def releasefn(tr, success): | |
1241 | repo = reporef() |
|
1250 | repo = reporef() | |
1242 | if success: |
|
1251 | if success: |
@@ -1063,3 +1063,99 b' repositories visible to an external hook' | |||||
1063 | rollback completed |
|
1063 | rollback completed | |
1064 | abort: pretxnclose hook exited with status 1 |
|
1064 | abort: pretxnclose hook exited with status 1 | |
1065 | [255] |
|
1065 | [255] | |
|
1066 | ||||
|
1067 | Check pretxnclose-bookmark can abort a transaction | |||
|
1068 | -------------------------------------------------- | |||
|
1069 | ||||
|
1070 | add hooks: | |||
|
1071 | ||||
|
1072 | * to prevent NEW bookmark on a non-public changeset | |||
|
1073 | * to prevent non-forward move of NEW bookmark | |||
|
1074 | ||||
|
1075 | $ cat << EOF >> .hg/hgrc | |||
|
1076 | > [hooks] | |||
|
1077 | > pretxnclose-bookmark.force-public = (echo \$HG_BOOKMARK| grep -v NEW > /dev/null) || [ -z "\$HG_NODE" ] || (hg log -r "\$HG_NODE" -T '{phase}' | grep public > /dev/null) | |||
|
1078 | > pretxnclose-bookmark.force-forward = (echo \$HG_BOOKMARK| grep -v NEW > /dev/null) || [ -z "\$HG_NODE" ] || (hg log -r "max(\$HG_OLDNODE::\$HG_NODE)" -T 'MATCH' | grep MATCH > /dev/null) | |||
|
1079 | > EOF | |||
|
1080 | ||||
|
1081 | $ hg log -G -T phases | |||
|
1082 | @ changeset: 6:81dcce76aa0b | |||
|
1083 | | tag: tip | |||
|
1084 | | phase: draft | |||
|
1085 | | parent: 4:125c9a1d6df6 | |||
|
1086 | | user: test | |||
|
1087 | | date: Thu Jan 01 00:00:00 1970 +0000 | |||
|
1088 | | summary: xx | |||
|
1089 | | | |||
|
1090 | | o changeset: 5:5fb12f0f2d51 | |||
|
1091 | | | branch: test | |||
|
1092 | | | bookmark: Z | |||
|
1093 | | | phase: draft | |||
|
1094 | | | parent: 3:9ba5f110a0b3 | |||
|
1095 | | | user: test | |||
|
1096 | | | date: Thu Jan 01 00:00:00 1970 +0000 | |||
|
1097 | | | summary: yy | |||
|
1098 | | | | |||
|
1099 | o | changeset: 4:125c9a1d6df6 | |||
|
1100 | | | bookmark: Y | |||
|
1101 | | | bookmark: Z@2 | |||
|
1102 | | | phase: public | |||
|
1103 | | | parent: 2:db815d6d32e6 | |||
|
1104 | | | user: test | |||
|
1105 | | | date: Thu Jan 01 00:00:00 1970 +0000 | |||
|
1106 | | | summary: x | |||
|
1107 | | | | |||
|
1108 | | o changeset: 3:9ba5f110a0b3 | |||
|
1109 | |/ branch: test | |||
|
1110 | | bookmark: foo | |||
|
1111 | | bookmark: four | |||
|
1112 | | phase: public | |||
|
1113 | | user: test | |||
|
1114 | | date: Thu Jan 01 00:00:00 1970 +0000 | |||
|
1115 | | summary: y | |||
|
1116 | | | |||
|
1117 | o changeset: 2:db815d6d32e6 | |||
|
1118 | | bookmark: foo@2 | |||
|
1119 | | bookmark: should-end-on-two | |||
|
1120 | | bookmark: x y | |||
|
1121 | | phase: public | |||
|
1122 | | parent: 0:f7b1eb17ad24 | |||
|
1123 | | user: test | |||
|
1124 | | date: Thu Jan 01 00:00:00 1970 +0000 | |||
|
1125 | | summary: 2 | |||
|
1126 | | | |||
|
1127 | | o changeset: 1:925d80f479bb | |||
|
1128 | |/ bookmark: X2 | |||
|
1129 | | bookmark: Z@1 | |||
|
1130 | | phase: public | |||
|
1131 | | user: test | |||
|
1132 | | date: Thu Jan 01 00:00:00 1970 +0000 | |||
|
1133 | | summary: 1 | |||
|
1134 | | | |||
|
1135 | o changeset: 0:f7b1eb17ad24 | |||
|
1136 | bookmark: foo@1 | |||
|
1137 | phase: public | |||
|
1138 | user: test | |||
|
1139 | date: Thu Jan 01 00:00:00 1970 +0000 | |||
|
1140 | summary: 0 | |||
|
1141 | ||||
|
1142 | ||||
|
1143 | attempt to create on a default changeset | |||
|
1144 | ||||
|
1145 | $ hg bookmark -r 81dcce76aa0b NEW | |||
|
1146 | transaction abort! | |||
|
1147 | rollback completed | |||
|
1148 | abort: pretxnclose-bookmark.force-public hook exited with status 1 | |||
|
1149 | [255] | |||
|
1150 | ||||
|
1151 | create on a public changeset | |||
|
1152 | ||||
|
1153 | $ hg bookmark -r 9ba5f110a0b3 NEW | |||
|
1154 | ||||
|
1155 | move to the other branch | |||
|
1156 | ||||
|
1157 | $ hg bookmark -f -r 125c9a1d6df6 NEW | |||
|
1158 | transaction abort! | |||
|
1159 | rollback completed | |||
|
1160 | abort: pretxnclose-bookmark.force-forward hook exited with status 1 | |||
|
1161 | [255] |
General Comments 0
You need to be logged in to leave comments.
Login now