在 Mercurial (hg) 更新时添加钩子

发布于 2024-11-09 15:24:18 字数 638 浏览 0 评论 0原文

我目前正在开发一个受 mercurial 控制的项目,我希望在更新时获得一个钩子来编辑 .htaccess fille 以避免更改 APPLICATION_ENV 为了适应“模式”,应用程序应该运行/加载配置/连接到数据库。

我的存储库结构如下:

Main dev repo (ENV : development)
    +-- Stable repo (Production version) (ENV : production)
    +-- Local dev repo (working version) (ENV : development)
        +-- Prototype repo (prototyping repo) (ENV : prototype)

我想要编辑的 .htaccess 部分如下(文件的第一行):

# Application var
SetEnv APPLICATION_ENV development

我不介意运行 python 脚本(或任何其他语言)我正在寻找右钩子以放入 .hg\hgrc 文件

I am currently working on a project which is under mercurial control and I was looking to get a hook upon update to edit the .htaccess fille to avoid changing the APPLICATION_ENV to fit the "mode" the application should run/load configs/connect to the database.

My repository structure goes as follow :

Main dev repo (ENV : development)
    +-- Stable repo (Production version) (ENV : production)
    +-- Local dev repo (working version) (ENV : development)
        +-- Prototype repo (prototyping repo) (ENV : prototype)

The part of the .htaccess I would like to have edited is the following (the first to lines of the file) :

# Application var
SetEnv APPLICATION_ENV development

I don't mind to run a python script ( or any other language) I am looking to the right hook to put in the .hg\hgrc file

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

厌倦 2024-11-16 15:24:18

这不是正确的做法,因为这会更改实际文件。您进行的下一次提交实际上会将更改提交到您的存储库。

相反,建议的方法是执行以下操作:

  1. 创建一个模板文件,并将其提交到您的存储库,即。 .htaccess.template
  2. 将实际文件 .htaccess 添加到 .hgignore 文件中,以使 Mercurial 避免在
  3. 本地,从模板复制一份文件到实际文件,然后编辑该文件,

这确保了对实际文件的更改,无论它们是什么,都不会提交到您的存储库。

一些配置系统还支持条件包含,这样您就可以像如果存在额外的配置文件 X,也加载 X,然后您将执行以下操作:

  1. 将实际文件提交到存储库,但使其简单化,包含默认值
  2. 用这样的包含语句结束文件
  3. 将要包含的文件的名称添加到 .hgignore 文件中,这样就不会提交这样的文件到存储库

这将确保任何人都可以添加通过添加自己的要包含的文件版本来更改或覆盖默认配置。

That's not the right thing to do, since that would change the actual file. The next commit you make you would actually commit that change to your repository.

Instead, the recommended approach is to do the following:

  1. Make a template file, and commit that to your repository, ie. .htaccess.template
  2. Add the actual file, .htaccess to the .hgignore file to make Mercurial avoid it
  3. Locally, make a copy from the template file to the actual file, and then edit that

This ensures that changes to the actual file, whatever they may be, will not be committed to your repository.

Some configuration systems also support conditional includes, so that you can something like if extra config file X exists, load X as well, and you would then do the following instead:

  1. Commit the actual file to the repository, but make it bare-bones, containing default values
  2. End the file with such an include-statement
  3. Add the name of the file you're including to the .hgignore file so that you won't commit such a file to the repository

This would ensure that anyone can add to or override the default configuration by adding their own version of that file that will be included.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文