Skip to content

Instantly share code, notes, and snippets.

@oyakata
Created July 29, 2011 08:10
Show Gist options
  • Save oyakata/1113427 to your computer and use it in GitHub Desktop.
Save oyakata/1113427 to your computer and use it in GitHub Desktop.
hg branchで数値のブランチを作るとリビジョン番号と混同して紛らわしいので生成不可能にするエクステンション。
[extensions]
sb=~/work/hgsmpl/myhgext/safe_branch.py
# pyファイルを置いた場所を指定して下さい。
# -*- coding:utf-8 -*-
import re
from mercurial import ui, hg, commands
MSG = """
指定したブランチの名前"%s"は数値です。
このブランチを作ると"%s"のリビジョン番号が使えなくなるのでやめて下さい。
とfeiz(https://twitter.com/#!/feiz)が申しております。
"""
def sb(ui_, repo, label=None):
if label and re.match(r"^[0-9]+$", label):
ui_.write(MSG % (label, label))
return
commands.branch(ui_, repo, label)
cmdtable = {
# "コマンド名": (関数, オプション, ヘルプ)
"sb": (sb, [], "safe branch")
}
if __name__ == "__main__":
import sys
ui_ = ui.ui()
args = sys.argv[1:]
label = args[0] if args else None
repo = hg.repository(ui_, ".", label)
sb(ui_, repo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment