deploy.rb
文件进行设置,其中之一是要部署的分支。我的问题是这样的:假设我从主干创建一个新的A分支。 部署文件将引用主干分支。 我编辑它,以便可以将A部署到测试环境中。 我完成了这个功能的工作,并将A分支合并到主干分支。 由于A中的
deploy.rb
文件更加新鲜,因此它被合并,现在master分支中的deploy.rb
引用A。 现在需要再次编辑。这看起来像很多看似不必要的手动编辑 - 参数应始终与当前分支名称匹配。 除此之外,很容易忘记每次都编辑设置。
最佳自动化此过程的方法是什么?
编辑:原来有人已经完全做到了我所需的:
This morning I had occasion to deploy a branch of a git repository to a staging server but hadn’t the foggiest idea how. A quick search through the capistrano source code revealed that I could use set
:branch "branch_name"
in my deploy script. I tried it and it worked. I then figured I would need to make a similar change across all my branches. Of course, I’m a lazy sod and wondered if there wasn’t a better way.If you’re not familiar with git, the output of the git branch command is a list of branches with an asterisk marking the one currently checked out on your local machine. For example:
> git branch * drupal_authentication fragment_caching master
So, I figured, what if I just parsed the output and searched for the branch marked as current:
set :branch, $1 if `git branch` =~ /\* (\S+)\s/m
Now I’m able to deploy whatever branch is current on my local machine from a single, shared, deploy script.