远程跟踪 Git 中的当前分支
我正在将连续测试转移到专用服务器(自动测试会使我的本地笔记本电脑速度减慢太多)。我希望我的测试服务器(恰好运行 CruiseControl.rb)能够通过 Git 不断获取我最新的(提交的)更改——理想情况下,我自己的工作流程不需要任何更改。我是唯一从事该项目的开发人员。
在获得测试服务器之前,我有:
- 我的笔记本电脑作为我的主要开发系统
- 我的本地存储库中有多个分支。
- 本地工作副本,指向其中一个分支。我经常在分支之间切换(通常是为了新功能)。
- 一个 GitHub 帐户,我经常将本地分支推送到镜像远程分支。 (这主要用于异地备份;我不会共享当前项目的任何代码)。我尝试至少在每个工作日结束时推送到 GitHub,尽管我偶尔会忘记。
我想保持所有这些完好无损。最重要的是,我现在拥有:
- 测试服务器
- ...正在运行 CruiseControl.rb
- 我的测试服务器上的笔记本电脑存储库的克隆。 (目前还没有克隆 GitHub)
- 测试服务器上的本地工作副本,CC 从中构建/测试。
- 这个工作副本指向一个特定的 Git 分支(当然),
我一直在尝试让我的测试服务器自动获取我在笔记本电脑工作副本上处理的任何分支并从中构建。 (这将模仿自动测试的连续测试,而不会消耗系统资源)。
我尝试过但没有成功的事情:
- git checkout origin/HEAD: 这可以使文件正常,但会破坏 CruiseControl,因为它不喜欢“无分支”工作副本。
- git checkout --track -b a_branch origin/a_branch:这对于获取文件来说效果很好,CC 喜欢它,但它将测试服务器固定到特定分支。当在笔记本电脑上切换分支时,我将有效地停止测试我当前的工作。
- git checkout --track -b my_testing_branch origin/HEAD:这也会获取可构建的文件,但它遇到与上面命令相同的问题。从 origin/HEAD 创建分支只会获取“默认”分支的 HEAD,因此它也是粘性的。
有什么方法可以让我获得一个良好的远程连续测试系统(有或没有 git 分支),并且不涉及对我的工作流程进行重大更改?
I'm moving my continuous testing to a dedicated server (autotest slows down my local laptop too much). What I'd like is for my testing server (which happens to be running CruiseControl.rb) to be continuously getting my latest (committed) changes via Git -- ideally, without any changes to my own workflow. I am the only developer working on this project.
Prior to getting the testing server, I had:
- My laptop as my main development system
- Multiple branches in my local repository.
- A local working copy, pointing to one of the branches. I switch between branches frequently (usually for new features).
- A GitHub account, to which I frequently push local branches to mirrored remote branches. (This is mostly for use an offsite backup; I'm not sharing any code for my current project). I try to push to GitHub at least at the end of every workday, though I occasionally forget.
I'd like to keep all of that intact. On top of that, I now have:
- The test server
- ...running CruiseControl.rb
- A clone of my laptop repository on my test server. (Currently it's not cloning GitHub)
- A local working copy on the test server, from which CC is building/testing.
- This working copy points to one particular Git branch (of course)
I've been trying to have my test server automatically get whatever branch I'm working on on my laptop working copy and build from that. (That would mimic autotest's continuous testing without eating up system resources).
Things I've tried without success:
- git checkout origin/HEAD: this gets the files fine but breaks CruiseControl because it doesn't like the "branchless" working copy.
- git checkout --track -b a_branch origin/a_branch: this works fine for getting files, and CC likes it, but it sticks the testing server to a particular branch. When switching branches on the laptop I'll effectively stop testing my current work.
- git checkout --track -b my_testing_branch origin/HEAD: this also gets buildable files, but it suffers from the same problem as the command above. Creating a branch from origin/HEAD only gets the HEAD for the "default" branch, so it's also sticky.
Is there any way I can get a good remote continuous testing system (with or without git branches) that doesn't involve major changes to my workflow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
另一种选择是编写一个 hook 来通知测试服务器要拉取的新代码。特别是,
post-commit
挂钩可能是更好的路线。然后,每次提交时,您都可以通知测试服务器要提取什么以及从哪个分支提取。Another option is to write a hook that notifies the test server of new code to pull. In particular, a
post-commit
hook is probably a better route. Then, every time you commit you can inform the test server of what to pull and from which branch.您可以有一个专用的测试分支,您可以在其中合并当前分支的工作。
您可以强制将该分支的内容替换为当前工作分支的提交(请参阅 git merge -s ours,“他们的”问题怎么样)。
然后在 CI 服务器上,您可以使用以下命令对其进行初始化:
这意味着笔记本电脑端的第一步是发布一些当前的工作以进行测试。
You could have a dedicated testing branch on which you merge your current branch work.
You can force replacing the content of that branch with the commit of the current working branch (see git merge -s ours, what about “their” question).
Then on the CI server, you initialize it with:
It implies one first step on the laptop side to publish some current work to test.
这不是最好的解决方案,但它是……
测试服务器可以运行 git remote show origin 来查看笔记本电脑上当前处于活动状态的分支。例如
,原始存储库当前位于 foo 分支上。
我还没有看到一个低级命令可以直接给你这个命令,所以你可能必须从中解析它(也许有人会有更好的方法)。例如,
现在,由于
origin/foo
的行为类似于origin/HEAD
(无本地分支),并且您的 CruiseControl 不喜欢这样,您可能应该创建一个本地分支在测试机器上,只需将其硬重置到最新位置:注意,这有点脆弱,因为
HEAD
me 并不总是你想象的那样。例如,在变基期间HEAD
将前后移动。如果您的测试服务器在变基期间检查笔记本电脑上的HEAD
,它可能会获得一些无效或不需要的位置。This isn't the greatest solution but it's something...
The test server can run
git remote show origin
to see which branch is currently active on your laptop. E.g.,So, the origin repository is currently on the
foo
branch.I haven't seen a low level command that will give you that directly so you may have to parse it out from this (perhaps someone will have a better way). Example,
Now, since
origin/foo
will act similar toorigin/HEAD
(no local branch) and your CruiseControl doesn't like that you should probably just create a local branch on the testing machine and simply hard-reset it to the latest location:Note, this is slightly fragile since
HEAD
me not always be what you think it is. For example, during a rebaseHEAD
will be moving backward and forward. If your testing server checksHEAD
on your laptop during a rebase it could get some invalid or undesired location.我认为通过颠倒两个系统之间的关系得到了一个很好的解决方案。我可以让笔记本电脑将更改推送到要测试的服务器,而不是让测试服务器从笔记本电脑的存储库中提取。
首先,我在笔记本电脑的存储库上添加一个遥控器:
然后,每当我有测试代码时,我都会进行推送:
这将在我当前所在的任何分支上工作。 -f 确保我会吹走该分支中已有的所有内容;我不必担心任何血统。
这实际上不会将最新代码放入工作副本中,但 CruiseControl 的轮询可以解决这个问题。我还可以有一个服务器端挂钩来更新工作副本并运行测试套件(那时我什至不需要 CC)。
我可能想向脚本或别名添加组合的提交+推送命令;这将给我一个命令提交和测试。如果出于某种原因我想在没有测试推送的情况下进行提交(反之亦然),那么我也有这些选项。
I've think got a pretty good solution by inverting the relationship between the two systems. Instead of having the test server pull from the laptop's repository, I could have the laptop push changes out to the server to be tested.
First I add a remote on the laptop's repo:
Then, whenever I have code for testing, I do a push:
This will work from whatever branch I'm currently on. The -f ensures that I'll blow away whatever is already in that branch; I won't have to worry about any ancestry.
This won't actually put the latest code in a working copy, but CruiseControl's polling can solve that. I could also have a server-side hook that updates a working copy and runs the test suite (I wouldn't even need CC at that point).
I'll probably want to add a combined commit+push command to a script or alias; that will give me my one-command commit & test. If for some reason I want to do a commit without a test push (or vice versa), then I have those options too.
在 GitHub 上托管并使用他们的 post-recieve hooks。这就是 Devver 和 RunCodeRun 执行它。
Host on GitHub and use their post-recieve hooks. That's how services like Devver and RunCodeRun do it.
我考虑过跳过 git 并转到共享文件夹/NFS/rsync 解决方案,但这有一个主要问题:它不是由提交触发/仅限于提交,所以我最终会得到误报损坏的构建,而我'我正在打字。
I've considered skipping past git and going to a shared folder/NFS/rsync solution, but that has one major problem: it's not triggered by / limited to commits, so I'll end up getting false-positive broken builds while I'm in the middle of typing something.