Git-gpush-scripts: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
h1. The git-gpush Script Suite | h1. The git-gpush Script Suite | ||
This page contains some background information for the git-gpush, git-gpick, and git-gpull scripts found in the | This page contains some background information for the git-gpush, git-gpick, and git-gpull scripts found in the "qt/qtrepotools repository":https://qt.gitorious.org/qt/qtrepotools. | ||
== Overview == | == Overview == | ||
Line 9: | Line 9: | ||
You may have noticed that these major features are geared towards making not ''your'' life easier, but that of your ''reviewers''. Until roles are switched, that is. | You may have noticed that these major features are geared towards making not ''your'' life easier, but that of your ''reviewers''. Until roles are switched, that is. | ||
The way how these scripts achieve this is by letting you manage | The way how these scripts achieve this is by letting you manage "virtual branches" (called "series") within your local working branch. When a series is pushed, its commits are rebased (usually to a commit from the upstream branch) to isolate it from other local Changes. The working tree is not affected by this in any way, so no unnecessary rebuilds result from this. | ||
== More Features == | == More Features == | ||
Line 28: | Line 28: | ||
* Notable differences from Gerrit's built-in copy&paste-able download command lines: | * Notable differences from Gerrit's built-in copy&paste-able download command lines: | ||
** Unlike 'cherry-pick', it can download an entire series in one go, so you just need to copy the Change-Id of the last Change and execute a single short command. | ** Unlike 'cherry-pick', it can download an entire series in one go, so you just need to copy the Change-Id of the last Change and execute a single short command. | ||
** Unlike 'checkout', your local Changes are not | ** Unlike 'checkout', your local Changes are not "hidden" on another branch, so you don't need to "switch contexts" (rebuild lots of stuff, deal with bugs you already fixed, etc.). | ||
** Unlike 'pull', no merge commit is introduced, so rebasing remains | ** Unlike 'pull', no merge commit is introduced, so rebasing remains "natural". | ||
* The downloaded Changes are a separate series, so there is no danger that you accidentally re-push them. | * The downloaded Changes are a separate series, so there is no danger that you accidentally re-push them. | ||
* Changes which already exist locally are replaced, so it is possible to pull in updates which have been pushed from other clones (or done directly on Gerrit). | * Changes which already exist locally are replaced, so it is possible to pull in updates which have been pushed from other clones (or done directly on Gerrit). | ||
Line 45: | Line 45: | ||
If you have pending Changes for the given branch on Gerrit, you need to synchronize the state:<br /><code><br />$ git gpick —check<br /></code> | If you have pending Changes for the given branch on Gerrit, you need to synchronize the state:<br /><code><br />$ git gpick —check<br /></code> | ||
Then create a series consisting of two Changes, and push it, adding two reviewers:<br /><code><br /> | Then create a series consisting of two Changes, and push it, adding two reviewers:<br /><code><br /><hack hack hack><br />$ git commit -a<br /><hack hack hack><br />$ git commit -a<br />$ git gpush –2 +someguy +anotherguy</code>example.com<br /><code> | ||
Amend and re-push the series:<br /></code><br />$ git rebase -i <code>{u}<br /> | Amend and re-push the series:<br /></code><br />$ git rebase -i <code>{u}<br /><…><br />$ git gpush<br /></code> | ||
Add another Change to the series:<br /><code><br /> | Add another Change to the series:<br /><code><br /><hack hack hack><br />$ git commit -a<br />$ git gpush -a<br /></code> | ||
<br />Re-push the series when it's not at the top any more:<br /><code><br />$ git gpush I123415affe:<br /></code> | <br />Re-push the series when it's not at the top any more:<br /><code><br />$ git gpush I123415affe:<br /></code> | ||
<br />Download somebody else's series:<br /><code><br />$ git gpick +I987ac23f1<br /></code> | <br />Download somebody else's series:<br /><code><br />$ git gpick +I987ac23f1<br /></code> | ||
Line 57: | Line 57: | ||
<br />h2. Answering Criticism | <br />h2. Answering Criticism | ||
<br />h4. Shouldn't this be implemented by the server instead of client-side scripts? | <br />h4. Shouldn't this be implemented by the server instead of client-side scripts? | ||
<br />Some of the problems could be addressed on the server side, but others are inherently client-side:<br />* The automatic | <br />Some of the problems could be addressed on the server side, but others are inherently client-side:<br />* The automatic "downbasing" to keep a Change's base constant even after it has been rebased locally could be done on the server, indeed.<br />* The management of series could- in principle - be done on the server. However:<br />'''''' This requires additional parameters which would need to be passed to git-receive-pack on Gerrit. Nobody wants to do that by hand, so you'd end up with a script ''anyway''.<br />'''''' This would upload unrelated Changes just to discard them immediately.<br />* The status report can be done by the server - in fact, it already is done, though without giving per-Change information. However, for obvious reasons this happens only ''after'' uploading the Changes, which means you lose the potential for entirely avoiding doomed uploads.<br />* The concurrent update overwrite protection is inherently client-side, as only the particular clone can know what was pushed from it the last time.<br />* The reviewer add function also needs to wrap git-receive-pack and thus invites client-side scripting.<br />* Identifying commits by Change-Id must be done client-side, as otherwise git doesn't even know what to push to the server.<br />* git-gpick is rather obviously a client-side tool. | ||
==== This changes my workflow! This is unacceptable! ==== | ==== This changes my workflow! This is unacceptable! ==== |
Revision as of 14:50, 24 February 2015
h1. The git-gpush Script Suite
This page contains some background information for the git-gpush, git-gpick, and git-gpull scripts found in the "qt/qtrepotools repository":https://qt.gitorious.org/qt/qtrepotools.
Overview
The general idea of these scripts is to make working with Gerrit more transparent:
* You can pull as often as you want, including right before pushing, as you would usually do in a git pull —rebase based workflow. Without git-gpush, this would unnecessarily rebase previously pushed Changes, which would make Gerrit's inter-diff feature slower and much less useful.
* You can keep many unrelated Changes locally without creating spurious dependencies between them on Gerrit. While you can achieve the same by having a separate local branch for every series, having all Changes in a single branch is much more convenient.
* You can push updates to specific Changes without invalidating reviews of unrelated Changes.
You may have noticed that these major features are geared towards making not your life easier, but that of your reviewers. Until roles are switched, that is.
The way how these scripts achieve this is by letting you manage "virtual branches" (called "series") within your local working branch. When a series is pushed, its commits are rebased (usually to a commit from the upstream branch) to isolate it from other local Changes. The working tree is not affected by this in any way, so no unnecessary rebuilds result from this.
More Features
git gpush
- The scripts remember which Changes belong to a series, so once you pushed it, the complete series can be identified by specifying a single Change (or none at all, if it's HEAD). This saves you from needing to keep track of how many Changes are in the series. You don't even need to use the currently last Change in the series. Also, commits can be specified by Change-Id. Taken together, these features make it possible to use the same command line to repeatedly re-push the same series regardless of any (interactive) rebasing and amending.
- An overview of the pushed Changes and their status relative to Gerrit is displayed.
- Pushes which would be rejected by Gerrit are detected upfront.
- Updates to the Changes pushed from other clones of the target repository (or made directly on Gerrit) are detected, so you won't accidentally overwrite them.
- WIP markers are detected and the Changes accordingly pushed as Drafts.
- Reviewers can be conveniently added by their IRC nickname.
git gpick
This script allows you to download pending Changes into your local branch, for local testing, reviewing and amending.
- Notable differences from Gerrit's built-in copy&paste-able download command lines:
- Unlike 'cherry-pick', it can download an entire series in one go, so you just need to copy the Change-Id of the last Change and execute a single short command.
- Unlike 'checkout', your local Changes are not "hidden" on another branch, so you don't need to "switch contexts" (rebuild lots of stuff, deal with bugs you already fixed, etc.).
- Unlike 'pull', no merge commit is introduced, so rebasing remains "natural".
- The downloaded Changes are a separate series, so there is no danger that you accidentally re-push them.
- Changes which already exist locally are replaced, so it is possible to pull in updates which have been pushed from other clones (or done directly on Gerrit).
- This checks for conflicts, so you won't lose concurrent local modifications.
- There also exists a mode which only checks for updates on Gerrit without replacing any local commits.
Examples
As usual, you should start with some solid RTFM: ;)
<br />$ git gpush -h<br />$ git gpick -h<br />$ git gpull -h<br />
Get all your pending changes on the current branch, in case you don't do this anyway:
<br />$ git cherry-pick …<br />
Alternatively, you could merge all your local branches and then rebase.
If you have pending Changes for the given branch on Gerrit, you need to synchronize the state:
<br />$ git gpick —check<br />
Then create a series consisting of two Changes, and push it, adding two reviewers:
<br /><hack hack hack><br />$ git commit -a<br /><hack hack hack><br />$ git commit -a<br />$ git gpush –2 +someguy +anotherguy
example.com
Amend and re-push the series:<br />
$ git rebase -i
{u}<br /><…><br />$ git gpush<br />
Add another Change to the series:
<br /><hack hack hack><br />$ git commit -a<br />$ git gpush -a<br />
Re-push the series when it's not at the top any more:
<br />$ git gpush I123415affe:<br />
Download somebody else's series:
<br />$ git gpick +I987ac23f1<br />
No need to worry about accidentally re-pushing it any more!
Update your local copy after somebody has been messing with your Change (gpush will tell you about it, so you won't overwrite the Changes accidentally):
<br />$ git gpick I9ce6d9e7a3<br />
pull/rebase your local series:
<br />$ git gpull<br />
h2. Answering Criticism
h4. Shouldn't this be implemented by the server instead of client-side scripts?
Some of the problems could be addressed on the server side, but others are inherently client-side:
* The automatic "downbasing" to keep a Change's base constant even after it has been rebased locally could be done on the server, indeed.
* The management of series could- in principle - be done on the server. However:
' This requires additional parameters which would need to be passed to git-receive-pack on Gerrit. Nobody wants to do that by hand, so you'd end up with a script anyway.
' This would upload unrelated Changes just to discard them immediately.
* The status report can be done by the server - in fact, it already is done, though without giving per-Change information. However, for obvious reasons this happens only after uploading the Changes, which means you lose the potential for entirely avoiding doomed uploads.
* The concurrent update overwrite protection is inherently client-side, as only the particular clone can know what was pushed from it the last time.
* The reviewer add function also needs to wrap git-receive-pack and thus invites client-side scripting.
* Identifying commits by Change-Id must be done client-side, as otherwise git doesn't even know what to push to the server.
* git-gpick is rather obviously a client-side tool.
This changes my workflow! This is unacceptable!
If you refuse to take advantage of the automated series management gpush offers, the only necessary change in workflow would be consistently using 'git gpush –1' for the first local Change and 'git gpush -a' for subsequent ones, instead of 'git push gerrit HEAD:refs/for/foo'. If you are convinced that this is inacceptable, you should probably rethink your priorities.
It's a new tool! It's harder for newbies!
Pushing to Gerrit already requires installing the Change-Id-creating commit-msg hook. Just cloning another (small) repository to get access to the scripts doesn't seem terribly hard in comparison. Also, qt5's init-repository script will clone the repository by default anyway, so the only thing necessary is adding the bin directory to git's PATH.
And the basic usage of gpush is unarguably easier than that of plain git.
It makes Qt different from other Gerrit-using projects!
These scrips are in no way specific to Qt. Anyone can use them with any Gerrit installation. Upstreaming will be considered at some point.