【问题标题】:Mercurial/Hg commit message prefixed with current branch directory以当前分支目录为前缀的 Mercurial/Hg 提交消息
【发布时间】:2012-05-04 06:41:25
【问题描述】:

我们将 Mercurial 与克隆存储库一起用于我们的“分支”。每个克隆中的“分支”都是“默认”。

结构是:

repos/Test
repos/Trunk
repos/Live
repos/NewFeature

在主干中完成工作后,更改将被拉入测试克隆。由于每次提交都是对default 完成的,现在我可以看到最初进行更改的位置,即在主干或测试存储库中。

我想知道如何自动为每条提交消息加上 [Trunk][Test] 前缀——这样日志会更容易查看。

我希望在从 cmd 行和从 Netbeans 提交时都发生这种情况。

【问题讨论】:

    标签: netbeans mercurial branch dvcs


    【解决方案1】:

    据我所知,没有此选项,也没有现有的 Mercurial 扩展。

    但是,我会考虑改用named branches:这样您就可以将当前分支名称直接嵌入到变更集中的元数据中。变更日志查看器通常会在其 UI 的显眼位置显示分支名称,以便轻松查看每个变更集所属的位置。

    【讨论】:

    • 我最初确实考虑过这一点,但由于我们必须在 3 或 4 个分支上同时开发,我认为克隆方法对我们来说更好。我们让 Jenkins 使用这种方法,我唯一想要的是提交消息前缀。我想我会调查一个预提交钩子......
    【解决方案2】:

    我们使用包含以下内容的脚本:

    import re,os,sys,mercurial,repo
    
    def prefix_commit_message(repo, **kwargs):
     commitctx = repo.commitctx
    
     def rewrite_ctx(ctx, error):
      branch_name = repo.root.split("/")[5]
      old_text = ctx._text
     ctx._text = "["+branch_name+"] "+old_text
    
     return commitctx(ctx, error)
    

    .hgrc 是这样的:

    $ cat ~/.hgrc
    [ui]
    username = Ian Wood
    
    [hooks]
    precommit = python:~/Development/repository/prepend-branch-name.py:prefix_commit_message
    

    【讨论】:

      【解决方案3】:

      mercurial wiki 包含许多关于如何设置commit message template 的建议。这负责命令行。

      至于 Netbeans,我不知道它是否会让您开箱即用。你总是可以write a plug-in

      【讨论】:

      • 谢谢 - 会看看这些建议。
      猜你喜欢
      • 2020-05-15
      • 1970-01-01
      • 2012-05-09
      • 2012-05-04
      • 2016-02-06
      • 1970-01-01
      • 1970-01-01
      • 2018-09-13
      • 1970-01-01
      相关资源
      最近更新 更多