如何在每个 git 分支上运行 makefile
我有一个包含多个分支的 git 存储库。存储库有一个在分支之间相同的 makefile。我想创建一个可以定期运行的 bash 脚本,该脚本从远程存储库中提取所有分支,然后为每个已更改或添加的分支运行 make 。然后,创建的可执行文件被移动到服务器上的另一个位置,并且在开始处理下一个分支之前将运行 make clean。
我运行的命令的顺序是:
make
cp executable /some/other/directory/branch_name
make clean
这是否可以用 shell 脚本来完成,如果是,我该如何实现它。如果 shell 脚本不适合此任务,我还能如何实现相同的结果?
I have a git repository with multiple branches. The repository has a makefile which is identical between branches. I'd like to create a bash script that can be run on a regular basis that pulls all branches from the remote repository and then runs make for every branch that has changed, or been added. The executable created is then moved to another location on the server, and a make clean would be run before beginning on the next branch to be processed.
The order of commands I'd be running would be
make
cp executable /some/other/directory/branch_name
make clean
Is this even possible to do with a shell script, if it is how could I go about implementing this. If a shell script is ill suited to this task, how else can I go about achieving the same result?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会做这样的事情:
首先获取的好处是您不必不必要地检查没有更改的分支;如果你的仓库很大,这可以节省时间。
显然,在处理错误方面需要做出选择;我只是选择了最简单但仍然有意义的事情。对于更复杂的处理,您可能需要执行
if make; 形式的操作。然后 ...;别的 ...; fi
,例如:I'd do something like this:
The nice thing about fetching first is that you don't have to unnecessarily check out branches with no changes; if your repo is big this can be a time-saver.
Obviously there are choices to be made about handling errors; I just went with the simplest thing that still made sense. For more complex handling, you might instead want to do things of the form
if make; then ...; else ...; fi
, e.g.:嗯, git pull 确实会生成输出,可以使用 grep 来确定更新了哪些引用。之后,只需使用
for ... in ...
循环循环grep
返回的匹配即可。Well,
git pull
does generate output that could begrep
'd to determine what refs were updated. After that it's a simple matter of looping over the matches returned bygrep
with afor ... in ...
loop.