aboutsummaryrefslogtreecommitdiff
path: root/git-codereview/util_test.go
AgeCommit message (Collapse)Author
2024-01-25git-codereview: remove usage of io/ioutilv1.9.0Joshua Sing
io/ioutil is now deprecated. Use non-deprecated equivalents. Change-Id: Iad1cc9c14dbdad3a6f9ada25072bc194bace4081 Reviewed-on: https://go-review.googlesource.com/c/review/+/543615 Reviewed-by: qiulaidongfeng <2645477756@qq.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2021-12-03git-codereview: log stderr and stdout from successful commandsBryan C. Mills
The reason for the failures in golang/go#49899 is not clear. Perhaps the stderr output will shed some light on what is happening. For golang/go#49899 Change-Id: I37c6339c8ebd4a37e4ff5b3b813572193903cee4 Reviewed-on: https://go-review.googlesource.com/c/review/+/368174 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-01-27git-codereview: avoid race in loadGerritOriginIan Lance Taylor
Use a mutex in loadGerritOrigin to avoid race when called in parallel by "git coderevew pending". Add a new initialized field so that the code knows when auth has been initialized. Adjust tests accordingly. The test is simply "go test -race". Fixes golang/go#43670 Change-Id: Ifb060fca6ed463f1d11a2959d03fca5e14e238c6 Reviewed-on: https://go-review.googlesource.com/c/review/+/287012 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-01-13git-codereview: add sync-branch -merge-back-to-parentRuss Cox
Dev branches come to an end. Making sync-branch help that process instead of forcing people to follow a playbook will help avoid mistakes. The flag name was chosen to be very unlikely to be used accidentally, and the commit subject and message both are distinct to make clear to reviewers what they are being asked to +2. The Merge List is also included in full and is likely to be quite large, yet another signal for everyone involved about the magnitude and weight of the change. Change-Id: I91cdda2b85cd3811711a339f4f3290fee109022e Reviewed-on: https://go-review.googlesource.com/c/review/+/282534 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-01-13git-codereview: new sync-branch and related fixesRuss Cox
This CL adds a new command, "git codereview sync-branch", which does the appropriate git merge for the current branch. This CL also fixes a bug in "git codereview branchpoint", and therefore also commands like "git codereview pending", which was getting the branchpoint wrong for merges, with the effect that a merge showed too many pending CLs. This CL also fixes a bug in "git codereview change", which was formerly willing to run "git checkout" with a pending merge, which had the effect of flattening the merge mysteriously. Now it detects the merge and refuses to run. All of this should make merges easier and less error-prone as we use dev branches more often. With the earlier CL in this stack that allows working directly on local branches, this is now a great way to run a merge updating dev.regabi: git change dev.regabi git sync-branch (with appropriate aliases to avoid typing "codereview"). Fixes golang/go#26201. Change-Id: Ic24603123ca5135a72004309f5bb208ff149c9eb Reviewed-on: https://go-review.googlesource.com/c/review/+/279772 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-01-07git-codereview: add a few more testsRuss Cox
Change-Id: I17ad065e8b4c1eb00cdd2f17af82be76bae4fc09 Reviewed-on: https://go-review.googlesource.com/c/review/+/279717 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-01-07git-codereview: update tests for "main" branch defaultRuss Cox
"git init ." leaves me on "main" now, not "master". Update tests to expect that, and update the "tracking" message too (otherwise the tests fail). Because not all gits agree about the initial branch name, set it explicitly too in the test. Fixes #42926. Change-Id: If3adb3bb53beba9efcd75cad0f081f59fba85fe7 Reviewed-on: https://go-review.googlesource.com/c/review/+/279873 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Austin Clements <austin@google.com>
2019-12-16git-codereview: write hooks with execute permission in testsBryan C. Mills
The 'write' helper function previously assumed file permission 0666. We don't actually need these files to be world-writable, but we do need specific ones — scripts executed as Git commit hooks — to be executable, at least on certain platforms. Also use t.Helper() to produce more useful log lines for failures. (That was added in order to diagnose TryBot failures.) Fixes golang/go#32836 Change-Id: I2d670563f42778ef8cf645445420756599c37ac6 Reviewed-on: https://go-review.googlesource.com/c/review/+/211477 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alexander Rakoczy <alex@golang.org>
2019-11-09git-codereview: override existing locale with LC_ALL=CEric Lagergren
The git-codereview tool shells out to git, then parses the output. However, because git respects a user's locale settings its output might not be in English, confusing git-codereview. Explicitly set the LC_ALL environment variable to the "C" locale, which is a version of US English that should be on all machines. Fixes golang/go#33895 Change-Id: Id06a81046dba58131fc1de602dd9add687846da1 Reviewed-on: https://go-review.googlesource.com/c/review/+/192237 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-08-23git-codereview: remove unused cruftJean de Klerk
Change-Id: If9b3494162311743d9ea84dc9dc26163d6563c9c Reviewed-on: https://go-review.googlesource.com/131055 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-03-30git-codereview: forbid mailing editor temp filesYury Smolsky
"mail" command rejects *~, #*# and .#* filenames. Also it should reject commit messages with non-printable characters, because these are impossible to spot in the review. For golang/go#24139 Change-Id: I3544e3c34c5ac9f55a7808264de4535bc455bd0a Reviewed-on: https://go-review.googlesource.com/101755 Run-TryBot: Yury Smolsky <yury@smolsky.by> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2017-12-15git-codereview: fix vet warning to fix build on Go 1.10Brad Fitzpatrick
Change-Id: Ib4cee24d5b70f99dfbebf0aa05c85be6164ba835 Reviewed-on: https://go-review.googlesource.com/84216 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-11-10git-codereview: batch GerritChange info fetches during pendingRuss Cox
This speeds pending a bit by reducing the number of round trips to the Gerrit server when you have a stack of CLs. Change-Id: I456e1a8739b9b6586f4e05c1a5442f402e440a79 Reviewed-on: https://go-review.googlesource.com/67571 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2017-07-17git-codereview: create hooks directory if it doesn't existMarko Mudrinic
Fixes golang/go#21028 On some versions of Git, "git init" will not create ".git/hooks directory", causing "git change" to fail. This fix will check if the hooks directory exists, and if not, create it. Change-Id: I6a9e688740fde8701e5d48630686039c8ebf4172 Reviewed-on: https://go-review.googlesource.com/49070 Reviewed-by: Kevin Burke <kev@inburke.com>
2016-03-02git-codereview: print git version when test fails to execute commandHåvard Haugen
Sample output when modifying one of the git commands: --- FAIL: TestSync (0.36s) util_test.go:250: git-codereview change work util_test.go:250: git-codereview sync util_test.go:207: in git-client/, ran [git add --does-not-exist file1] with git version 1.9.1: exit status 129 error: unknown option `does-not-exist' usage: git add [options] [--] <pathspec>... -n, --dry-run dry run -v, --verbose be verbose -i, --interactive interactive picking -p, --patch select hunks interactively -e, --edit edit current diff and apply -f, --force allow adding otherwise ignored files -u, --update update tracked files -N, --intent-to-add record only the fact that the path will be added later -A, --all add changes from all tracked and untracked files --ignore-removal ignore paths removed in the working tree (same as --no-all) --refresh don't add, only refresh the index --ignore-errors just skip files which cannot be added because of errors --ignore-missing check if - even missing - files are ignored in dry run Updates golang/go#9602. Change-Id: Ibeb93b1f3f4da43d1f95fd0eb5f2c372210cd6b3 Reviewed-on: https://go-review.googlesource.com/9952 Reviewed-by: Andrew Gerrand <adg@golang.org> Run-TryBot: Andrew Gerrand <adg@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-02-18git-codereview: disable Gerrit-specific hook behavior if Gerrit is not in useRuss Cox
Every time I accidentally type 'git pending' in a non-Gerrit repository, that command installs hooks, and then I have to zero the hook files to keep working. First, don't install the hooks if this looks like a non-Gerrit git repo. That seems like it will play well with others. But, people might also want to use the non-Gerrit parts of the tool, so if people do say 'git codereview hooks', let that install them. And then if the hooks are invoked in a non-Gerrit repo, selectively disable the Gerrit-specific parts. For example, if it's not a Gerrit repo we might still want to check and fix 'Fixes #N' lines if directed by the config, but we don't want to add Change-Id lines. Now that things are a bit better behaved, also leave the hooks on in detached head mode. I've found that it's quite frustrating not to have the hooks on when working midway through git rebase -i. If we find reasons that the hooks were off we can try to figure out how to split the difference. Fixes golang/go#12170. Change-Id: I69fa156ce4fd11c0c84416088cd972957ce1ce6d Reviewed-on: https://go-review.googlesource.com/19560 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Austin Clements <austin@google.com>
2015-11-11git-codereview: allow multiple commit hashes for submitAustin Clements
This adds support to the submit subcommand for passing and submitting multiple commit hashes. Change-Id: Id030b07cac21d11acbeb8015fde9cb9e1acb1479 Reviewed-on: https://go-review.googlesource.com/16674 Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-08-18git-codereview: skip git tests when there's no gitRuss Cox
To fix linux builders for golang/go#11811. Change-Id: I8058e09bc39c374ab9af469b2a6c732be14453f2 Reviewed-on: https://go-review.googlesource.com/13692 Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-13git-codereview: deflake TestSyncRebaseHåvard Haugen
In order to guarantee different hashes on "client" and "server" we need to generate different commit histories. Fixes golang/go#10048. Updates golang/go#9602. Change-Id: I511f517639230d7aca74b3d2ce3bfa6a2c299a5c Reviewed-on: https://go-review.googlesource.com/9951 Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-05-11Revert "git-codereview: deflake TestSyncRebase"Andrew Gerrand
This reverts commit dd3919343ed6ab8cad672c16b8c2a514615d9c4e. Change-Id: Ifa77bd8182f832c1e8553dac8f3f4a87a1db64fa Reviewed-on: https://go-review.googlesource.com/9940 Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-05-11git-codereview: deflake TestSyncRebaseHåvard Haugen
In order to guarantee different hashes on "client" and "server" we need to generate different commit histories. Fixes golang/go#10048, updates golang/go#9602. Change-Id: I42a50dc890598dd3a3b6c626c6db70ffe06c14d3 Reviewed-on: https://go-review.googlesource.com/9256 Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-04-09git-codereview: reject commits with multiple Change-Id linesJosh Bleecher Snyder
This should help prevent the situation in CL 8653. Change-Id: I03e4868656a86e69e11f3e0545feb1681fb0f628 Reviewed-on: https://go-review.googlesource.com/8671 Reviewed-by: Minux Ma <minux@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2015-02-05Revert "git-codereview: work around compiler bug"Minux Ma
The compiler bug (golang/go#9738) has been fixed by CL 3690. This reverts commit 18314f7ef99b73828d56cef081ee5a9572fe902c. Change-Id: I313f19a57f74301841746d45437b945e3b0fc768 Reviewed-on: https://go-review.googlesource.com/3930 Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-30git-codereview: fix bug in sync for multi-commit clientRuss Cox
When deciding whether to discard the commit info for the final commit, it was using the first commit instead of the final one. Change-Id: I2304fba6fa82a1d21600c3caa08b6b119edcdb7f Reviewed-on: https://go-review.googlesource.com/3628 Reviewed-by: Rob Pike <r@golang.org>
2015-01-30git-codereview: revise pendingRuss Cox
- Use multiple commit output form always. We're going to start suggesting the use of multiple commits, and it is confusing to flip between the two displays based on the number of commits. - Document pending -c option (current branch only). - Add pending -s option (short form). While doing this, I got my client into a state where I had a tag and a branch with the same name. Make things work in that mode too. Change-Id: I4a3d73ce88be78b04d5bc4e56f1e3bed435cfde7 Reviewed-on: https://go-review.googlesource.com/3621 Reviewed-by: Andrew Gerrand <adg@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2015-01-30git-codereview: work around compiler bugRuss Cox
Using the 'return &gitTest{...}' form the gt variable is not set during the deferred func execution, causing the tmp dir to be removed always, making all the tests fail. Issue golang/go#9738. Change-Id: Iac91926ea5d756547eaade52effe68bc7706c17a Reviewed-on: https://go-review.googlesource.com/3620 Reviewed-by: Andrew Gerrand <adg@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2015-01-21git-codereview: use fromSlash in TestGofmtSubdir* to make them pass on windowsAlex Brainman
Change-Id: Ic59299a544d2a8887b305b202c0f5da758ff7322 Reviewed-on: https://go-review.googlesource.com/3071 Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-19git-codereview: work around git checkout-index bug in gofmtRuss Cox
If you run 'git gofmt' when files in the working directory differ from modified files in the index and you are running the command not from that working directory or a parent, then git checkout-index --temp (used by git gofmt) will print mangled path names, confusing git gofmt. The most common error this causes is: git-codereview: gofmt reported errors: stat : no such file or directory although there are other possible ways it can fail. I've reported the git bug, which will be fixed in Git 2.3.0. Work around the bug by always invoking git checkout-index in the repo root. Fixes #9476. Change-Id: Ifcbdfd4a966dd21518dd95ceacd81a1679048e3c Reviewed-on: https://go-review.googlesource.com/2907 Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-01-16git-codereview: cleanup tmp directory if newGitTest fails.Hyang-Ah Hana Kim
This sets up a deferred os.RemoveAll call that runs only if newGitTest fails to return a gitTest instance. Change-Id: I62814e47d2cf152e3b5fcb3dd07da8df2fb63091 Reviewed-on: https://go-review.googlesource.com/2900 Reviewed-by: Andrew Gerrand <adg@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-14git-codereview: do not gofmt committed files during mergeRuss Cox
Change-Id: Ie772b8f46587ad0d56350b697e75601f45b4c393 Reviewed-on: https://go-review.googlesource.com/2785 Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-01-14git-codereview: add branchpoint command, for scriptsRuss Cox
The most important use of this is git rebase -i $(git codereview branchpoint) in multichange clients. Change-Id: I6bdbc02db2e2823e837159efec20ad5c9046bcd5 Reviewed-on: https://go-review.googlesource.com/2783 Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-01-06git-codereview: begin to handle multiple-change branchesRuss Cox
Gerrit supports multiple-change branches, and we'd like to make git-codereview useful for people using this mode of work. This CL is the first step. - remove error message on detecting a multiple-change branch - require 'git submit hash' in multiple-change branch - make git submit, git sync cleanup safe for multiple-change branch - adjust git pending output to show full information about multiple-change branch - add pending -c to show only current branch, since output is getting long We're not advertising or supporting this mode yet. For now the only way to enter it is to run 'git commit' to create the second commit. Perhaps eventually we will support something like 'git change -new'. Change-Id: I8284a7c230503061d3e6d7cce0be7d8d05c9b2a3 Reviewed-on: https://go-review.googlesource.com/2110 Reviewed-by: Andrew Gerrand <adg@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2015-01-06git-codereview: allow short user names in git mailRuss Cox
In Mercurial, hg mail expanded Rietveld user names. There are no Gerrit user names. There are GitHub user names, but then I'd have to type randall77,griesemer,robpike,ianlancetaylor instead of khr,gri,r,iant. The algorithm for expanding short user names is as follows: Look at the git commit log for the current repository, extracting all the email addresses in Reviewed-By lines and sorting by how many times each address appears. For each short user name, walk the list, most common address first, and use the first address found that has the short user name on the left side of the @. This is a purely local operation, it adjusts automatically as new reviewers come on board, it avoids a separate database, it adjusts to repo-specific reviewer patterns, and it resolves potential ambiguity in favor of the most common reviewers. (For example, r@golang.org will beat any other r@mail.com in the main repo.) Change-Id: I53afea2a86ba4cfa8fd7f31d56b90a3e12cc2b48 Reviewed-on: https://go-review.googlesource.com/2111 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-01-06git-codereview: make tests pass on windowsAlex Brainman
- "git gofmt" uses "git checkout-index" command that is broken if used with many arguments - limit number of arguments passed to "git checkout-index"; - change / into \ on windows when matching git output on windows; - add .gitattributes to test repository to make it look more like all real Go repositories; - make sure no files left behind in /tmp on windows. Fixes golang/go#9433. Change-Id: Ifceacfffd1cd4b02190d7e941611d0d0f3c48cdd Reviewed-on: https://go-review.googlesource.com/2089 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-24git-codereview: set user.name and user.email before testsShenghou Ma
The tests should not assume that the user running the tests have global user.name and user.email settings in ~/.gitconfig. This applies especially to the builder machines. Fixes golang/go#9342, and golang/go#9433. Change-Id: Ic1c973b133586edfa6dce3a169b7512db113fcc6 Signed-off-by: Shenghou Ma <minux@golang.org> Reviewed-on: https://go-review.googlesource.com/2117 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-23git-codereview: fix a few corner case failuresRuss Cox
- make it clearer what the random git command at the end of failures means - avoid some problems with detached HEAD mode in hooks run during git rebase - redirect all stdout/stderr into test buffers Change-Id: I102f22fc870f69c884728eaa46ecc95792d5b795 Reviewed-on: https://go-review.googlesource.com/2011 Reviewed-by: Andrew Gerrand <adg@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2014-12-18git-codereview: rename from 'git-review' to 'git-codereview'Andrew Gerrand
Mostly trivial search and replace, except for hooks.go which includes a special case to remove the old git-review hooks. Change-Id: Ic0792bb3e26607e5e0ead88958e46c3ac08288cd Reviewed-on: https://go-review.googlesource.com/1741 Reviewed-by: Russ Cox <rsc@golang.org>