diff options
Diffstat (limited to 'git-codereview')
| -rw-r--r-- | git-codereview/branch_test.go | 26 | ||||
| -rw-r--r-- | git-codereview/change_test.go | 28 | ||||
| -rw-r--r-- | git-codereview/gofmt_test.go | 16 | ||||
| -rw-r--r-- | git-codereview/hook_test.go | 4 | ||||
| -rw-r--r-- | git-codereview/mail_test.go | 22 | ||||
| -rw-r--r-- | git-codereview/pending.go | 2 | ||||
| -rw-r--r-- | git-codereview/pending_test.go | 22 | ||||
| -rw-r--r-- | git-codereview/submit_test.go | 22 | ||||
| -rw-r--r-- | git-codereview/util_test.go | 25 |
9 files changed, 90 insertions, 77 deletions
diff --git a/git-codereview/branch_test.go b/git-codereview/branch_test.go index d5b8a43..438ff39 100644 --- a/git-codereview/branch_test.go +++ b/git-codereview/branch_test.go @@ -14,17 +14,17 @@ func TestCurrentBranch(t *testing.T) { gt := newGitTest(t) defer gt.done() - t.Logf("on master") - checkCurrentBranch(t, "master", "origin/master", false, false, "", "") + t.Logf("on main") + checkCurrentBranch(t, "main", "origin/main", false, false, "", "") t.Logf("on newbranch") trun(t, gt.client, "git", "checkout", "--no-track", "-b", "newbranch") - checkCurrentBranch(t, "newbranch", "origin/master", true, false, "", "") + checkCurrentBranch(t, "newbranch", "origin/main", true, false, "", "") t.Logf("making change") write(t, gt.client+"/file", "i made a change", 0644) trun(t, gt.client, "git", "commit", "-a", "-m", "My change line.\n\nChange-Id: I0123456789abcdef0123456789abcdef\n") - checkCurrentBranch(t, "newbranch", "origin/master", true, true, "I0123456789abcdef0123456789abcdef", "My change line.") + checkCurrentBranch(t, "newbranch", "origin/main", true, true, "I0123456789abcdef0123456789abcdef", "My change line.") t.Logf("on dev.branch") trun(t, gt.client, "git", "checkout", "-t", "-b", "dev.branch", "origin/dev.branch") @@ -73,16 +73,16 @@ func TestLocalBranches(t *testing.T) { gt := newGitTest(t) defer gt.done() - t.Logf("on master") - checkLocalBranches(t, "master") + t.Logf("on main") + checkLocalBranches(t, "main") t.Logf("on dev branch") trun(t, gt.client, "git", "checkout", "-b", "newbranch") - checkLocalBranches(t, "master", "newbranch") + checkLocalBranches(t, "main", "newbranch") t.Logf("detached head mode") trun(t, gt.client, "git", "checkout", "HEAD^0") - checkLocalBranches(t, "HEAD", "master", "newbranch") + checkLocalBranches(t, "HEAD", "main", "newbranch") } func checkLocalBranches(t *testing.T, want ...string) { @@ -103,9 +103,9 @@ func TestAmbiguousRevision(t *testing.T) { t.Logf("creating file paths that conflict with revision parameters") mkdir(t, gt.client+"/origin") - write(t, gt.client+"/origin/master..work", "Uh-Oh! SpaghettiOs", 0644) + write(t, gt.client+"/origin/main..work", "Uh-Oh! SpaghettiOs", 0644) mkdir(t, gt.client+"/work..origin") - write(t, gt.client+"/work..origin/master", "Be sure to drink your Ovaltine", 0644) + write(t, gt.client+"/work..origin/main", "Be sure to drink your Ovaltine", 0644) b := CurrentBranch() b.Submitted("I123456789") @@ -159,12 +159,12 @@ func TestBranchpointMerge(t *testing.T) { gt := newGitTest(t) defer gt.done() - // commit more work on master + // commit more work on main write(t, gt.server+"/file", "more work", 0644) trun(t, gt.server, "git", "commit", "-m", "work", "file") // update client - trun(t, gt.client, "git", "checkout", "master") + trun(t, gt.client, "git", "checkout", "main") trun(t, gt.client, "git", "pull") hash := strings.TrimSpace(trun(t, gt.client, "git", "rev-parse", "HEAD")) @@ -178,7 +178,7 @@ func TestBranchpointMerge(t *testing.T) { if bp != hash { t.Logf("branches:\n%s", trun(t, gt.client, "git", "branch", "-a", "-v")) t.Logf("log:\n%s", trun(t, gt.client, "git", "log", "--graph", "--decorate")) - t.Logf("log origin/master..HEAD:\n%s", trun(t, gt.client, "git", "log", "origin/master..HEAD")) + t.Logf("log origin/main..HEAD:\n%s", trun(t, gt.client, "git", "log", "origin/main..HEAD")) t.Fatalf("branchpoint=%q, want %q", bp, hash) } } diff --git a/git-codereview/change_test.go b/git-codereview/change_test.go index e9337dc..206ed82 100644 --- a/git-codereview/change_test.go +++ b/git-codereview/change_test.go @@ -14,28 +14,28 @@ func TestChange(t *testing.T) { gt := newGitTest(t) defer gt.done() - t.Logf("master -> master") - testMain(t, "change", "master") - testRan(t, "git checkout -q master") + t.Logf("main -> main") + testMain(t, "change", "main") + testRan(t, "git checkout -q main") testCommitMsg = "foo: my commit msg" - t.Logf("master -> work") + t.Logf("main -> work") testMain(t, "change", "work") testRan(t, "git checkout -q -b work", - "git branch -q --set-upstream-to origin/master") + "git branch -q --set-upstream-to origin/main") - t.Logf("work -> master") - testMain(t, "change", "master") - testRan(t, "git checkout -q master") + t.Logf("work -> main") + testMain(t, "change", "main") + testRan(t, "git checkout -q main") - t.Logf("master -> work with staged changes") + t.Logf("main -> work with staged changes") write(t, gt.client+"/file", "new content", 0644) trun(t, gt.client, "git", "add", "file") testMain(t, "change", "work") testRan(t, "git checkout -q work", "git commit -q --allow-empty -m foo: my commit msg") - t.Logf("master -> dev.branch") + t.Logf("main -> dev.branch") testMain(t, "change", "dev.branch") testRan(t, "git checkout -q -t -b dev.branch origin/dev.branch") } @@ -52,13 +52,13 @@ func TestChangeAhead(t *testing.T) { gt := newGitTest(t) defer gt.done() - // commit to master (mistake) + // commit to main (mistake) write(t, gt.client+"/file", "new content", 0644) trun(t, gt.client, "git", "add", "file") trun(t, gt.client, "git", "commit", "-m", "msg") testMainDied(t, "change", "work") - testPrintedStderr(t, "bad repo state: branch master is ahead of origin/master") + testPrintedStderr(t, "bad repo state: branch main is ahead of origin/main") } func TestMessageRE(t *testing.T) { @@ -117,7 +117,7 @@ func TestChangeCL(t *testing.T) { // Ensure that 'change' with a CL accepts we have gerrit. Test address is injected by newGerritServer. write(t, gt.server+"/codereview.cfg", "gerrit: on", 0644) trun(t, gt.server, "git", "add", "codereview.cfg") - trun(t, gt.server, "git", "commit", "-m", "codereview.cfg on master") + trun(t, gt.server, "git", "commit", "-m", "codereview.cfg on main") trun(t, gt.client, "git", "pull") defer srv.done() @@ -140,7 +140,7 @@ func TestChangeCL(t *testing.T) { }}) checkChangeCL := func(arg, ref, hash string) { - testMain(t, "change", "master") + testMain(t, "change", "main") testMain(t, "change", arg) testRan(t, fmt.Sprintf("git fetch -q origin %s", ref), diff --git a/git-codereview/gofmt_test.go b/git-codereview/gofmt_test.go index 0bd6aa9..81f82a4 100644 --- a/git-codereview/gofmt_test.go +++ b/git-codereview/gofmt_test.go @@ -255,33 +255,33 @@ func TestGofmtFastForwardMerge(t *testing.T) { gt := newGitTest(t) defer gt.done() - // merge dev.branch into master + // merge dev.branch into main write(t, gt.server+"/file", "more work", 0644) trun(t, gt.server, "git", "commit", "-m", "work", "file") trun(t, gt.server, "git", "merge", "-m", "merge", "dev.branch") - // add bad go file on master + // add bad go file on main write(t, gt.server+"/bad.go", "package {\n", 0644) trun(t, gt.server, "git", "add", "bad.go") trun(t, gt.server, "git", "commit", "-m", "bad go") // update client - trun(t, gt.client, "git", "checkout", "master") + trun(t, gt.client, "git", "checkout", "main") trun(t, gt.client, "git", "pull") testMain(t, "change", "dev.branch") trun(t, gt.client, "git", "pull") - // merge master into dev.branch, fast forward merge - trun(t, gt.client, "git", "merge", "--ff-only", "master") + // merge main into dev.branch, fast forward merge + trun(t, gt.client, "git", "merge", "--ff-only", "main") // verify that now client is in a state where just the tag is changing; there's no new commit. - masterHash := strings.TrimSpace(trun(t, gt.server, "git", "rev-parse", "master")) + mainHash := strings.TrimSpace(trun(t, gt.server, "git", "rev-parse", "main")) devHash := strings.TrimSpace(trun(t, gt.client, "git", "rev-parse", "HEAD")) - if masterHash != devHash { + if mainHash != devHash { t.Logf("branches:\n%s", trun(t, gt.client, "git", "branch", "-a", "-v")) t.Logf("log:\n%s", trun(t, gt.client, "git", "log", "--graph", "--decorate")) - t.Fatalf("setup wrong - got different commit hashes on master and dev branch") + t.Fatalf("setup wrong - got different commit hashes on main and dev branch") } // check that gofmt finds nothing to do, ignoring the bad (but committed) file1.go. diff --git a/git-codereview/hook_test.go b/git-codereview/hook_test.go index e9dc1c3..d4ffbc4 100644 --- a/git-codereview/hook_test.go +++ b/git-codereview/hook_test.go @@ -210,10 +210,10 @@ func testHookCommitMsgBranchPrefix(t *testing.T, gerrit bool) { } // Master has no prefix. - testMain(t, "change", "master") + testMain(t, "change", "main") checkPrefix("Test message.\n") - // Work branch from master has no prefix. + // Work branch from main has no prefix. testMain(t, "change", "work") checkPrefix("Test message.\n") } diff --git a/git-codereview/mail_test.go b/git-codereview/mail_test.go index c655b54..b754d3b 100644 --- a/git-codereview/mail_test.go +++ b/git-codereview/mail_test.go @@ -26,7 +26,7 @@ func TestMail(t *testing.T) { testMain(t, "mail") testRan(t, - "git push -q origin HEAD:refs/for/master", + "git push -q origin HEAD:refs/for/main", "git tag -f work.mailed "+h) } @@ -153,14 +153,14 @@ func TestMailMultiple(t *testing.T) { h := CurrentBranch().Pending()[1].ShortHash testMain(t, "mail", "HEAD^") testRan(t, - "git push -q origin "+h+":refs/for/master", + "git push -q origin "+h+":refs/for/main", "git tag -f work.mailed "+h) // Mail HEAD. h = CurrentBranch().Pending()[0].ShortHash testMain(t, "mail", "HEAD") testRan(t, - "git push -q origin HEAD:refs/for/master", + "git push -q origin HEAD:refs/for/main", "git tag -f work.mailed "+h) } @@ -203,17 +203,17 @@ func TestMailShort(t *testing.T) { testMain(t, "mail") testRan(t, - "git push -q origin HEAD:refs/for/master", + "git push -q origin HEAD:refs/for/main", "git tag -f work.mailed "+h) testMain(t, "mail", "-r", "r1") testRan(t, - "git push -q origin HEAD:refs/for/master%r=r1@golang.org", + "git push -q origin HEAD:refs/for/main%r=r1@golang.org", "git tag -f work.mailed "+h) testMain(t, "mail", "-r", "other,anon", "-cc", "r1,full@email.com") testRan(t, - "git push -q origin HEAD:refs/for/master%r=other@golang.org,r=anon@golang.org,cc=r1@golang.org,cc=full@email.com", + "git push -q origin HEAD:refs/for/main%r=other@golang.org,r=anon@golang.org,cc=r1@golang.org,cc=full@email.com", "git tag -f work.mailed "+h) testMainDied(t, "mail", "-r", "other", "-r", "anon,r1,missing") @@ -229,7 +229,7 @@ func TestWIP(t *testing.T) { testMain(t, "mail", "-wip") testRan(t, - "git push -q origin HEAD:refs/for/master%wip", + "git push -q origin HEAD:refs/for/main%wip", "git tag -f work.mailed "+h) } @@ -253,7 +253,7 @@ func TestMailTopic(t *testing.T) { testMain(t, "mail", "-topic", "test-topic") testRan(t, - "git push -q origin HEAD:refs/for/master%topic=test-topic", + "git push -q origin HEAD:refs/for/main%topic=test-topic", "git tag -f work.mailed "+h) } @@ -274,11 +274,11 @@ func TestMailHashtag(t *testing.T) { testMain(t, "mail", "-hashtag", "test1,test2") testRan(t, - "git push -q origin HEAD:refs/for/master%hashtag=test1,hashtag=test2", + "git push -q origin HEAD:refs/for/main%hashtag=test1,hashtag=test2", "git tag -f work.mailed "+h) testMain(t, "mail", "-hashtag", "") testRan(t, - "git push -q origin HEAD:refs/for/master", + "git push -q origin HEAD:refs/for/main", "git tag -f work.mailed "+h) testMainDied(t, "mail", "-hashtag", "test1,,test3") @@ -299,7 +299,7 @@ func TestMailEmpty(t *testing.T) { testMain(t, "change", "work") testRan(t, "git checkout -q -b work", - "git branch -q --set-upstream-to origin/master") + "git branch -q --set-upstream-to origin/main") t.Logf("creating empty change") testCommitMsg = "foo: this commit will be empty" diff --git a/git-codereview/pending.go b/git-codereview/pending.go index bd8d508..e17a905 100644 --- a/git-codereview/pending.go +++ b/git-codereview/pending.go @@ -247,7 +247,7 @@ func cmdPending(args []string) { if n := b.CommitsBehind(); n > 0 { tags = append(tags, fmt.Sprintf("%d behind", n)) } - if b.OriginBranch() != "origin/master" { + if br := b.OriginBranch(); br != "origin/master" && br != "origin/main" { tags = append(tags, "tracking "+strings.TrimPrefix(b.OriginBranch(), "origin/")) } if len(tags) > 0 { diff --git a/git-codereview/pending_test.go b/git-codereview/pending_test.go index ee5e947..ccb2f76 100644 --- a/git-codereview/pending_test.go +++ b/git-codereview/pending_test.go @@ -22,7 +22,7 @@ func TestPendingNone(t *testing.T) { defer gt.done() testPending(t, ` - master (current branch) + main (current branch) `) } @@ -69,13 +69,13 @@ func TestPendingComplex(t *testing.T) { trun(t, gt.server, "git", "commit", "-a", "-m", "v3") trun(t, gt.client, "git", "fetch") - trun(t, gt.client, "git", "checkout", "-b", "work3ignored", "-t", "origin/master") + trun(t, gt.client, "git", "checkout", "-b", "work3ignored", "-t", "origin/main") write(t, gt.server+"/file", "v4", 0644) trun(t, gt.server, "git", "commit", "-a", "-m", "v4") trun(t, gt.client, "git", "fetch") - trun(t, gt.client, "git", "checkout", "-b", "work2", "-t", "origin/master") + trun(t, gt.client, "git", "checkout", "-b", "work2", "-t", "origin/main") write(t, gt.client+"/file", "modify", 0644) write(t, gt.client+"/file1", "new", 0644) trun(t, gt.client, "git", "add", "file", "file1") @@ -159,14 +159,14 @@ func TestPendingErrors(t *testing.T) { gt.enableGerrit(t) defer gt.done() - trun(t, gt.client, "git", "checkout", "master") + trun(t, gt.client, "git", "checkout", "main") write(t, gt.client+"/file", "v3", 0644) trun(t, gt.client, "git", "commit", "-a", "-m", "v3") testPending(t, ` - master REVHASH..REVHASH (current branch) - ERROR: Branch contains 1 commit not on origin/master. - Do not commit directly to master branch. + main REVHASH..REVHASH (current branch) + ERROR: Branch contains 1 commit not on origin/main. + Do not commit directly to main branch. + REVHASH v3 @@ -177,9 +177,9 @@ func TestPendingErrors(t *testing.T) { `) testPendingArgs(t, []string{"-s"}, ` - master REVHASH..REVHASH (current branch) - ERROR: Branch contains 1 commit not on origin/master. - Do not commit directly to master branch. + main REVHASH..REVHASH (current branch) + ERROR: Branch contains 1 commit not on origin/main. + Do not commit directly to main branch. + REVHASH v3 `) @@ -446,7 +446,7 @@ func TestPendingGerritMultiChange15(t *testing.T) { func testPendingReply(srv *gerritServer, id, rev, status string) { srv.setJSON(id, `{ - "id": "proj~master~`+id+`", + "id": "proj~main~`+id+`", "project": "proj", "current_revision": "`+rev+`", "status": "`+status+`", diff --git a/git-codereview/submit_test.go b/git-codereview/submit_test.go index 3f893ec..fbe2cb3 100644 --- a/git-codereview/submit_test.go +++ b/git-codereview/submit_test.go @@ -94,9 +94,9 @@ func TestSubmitErrors(t *testing.T) { t.Logf("> submit with unexpected status") const newJSON = `{"status": "NEW", "labels": {"Code-Review": {"approved": {}}}}` srv.setJSON(id, newJSON) - srv.setReply("/a/changes/proj~master~I123456789/submit", gerritReply{body: ")]}'\n" + newJSON}) + srv.setReply("/a/changes/proj~main~I123456789/submit", gerritReply{body: ")]}'\n" + newJSON}) testMainDied(t, "submit") - testRan(t, "git push -q origin HEAD:refs/for/master") + testRan(t, "git push -q origin HEAD:refs/for/main") testPrintedStderr(t, "submit error: unexpected post-submit Gerrit change status \"NEW\"") } @@ -109,15 +109,15 @@ func TestSubmitTimeout(t *testing.T) { gt.work(t) setJSON := func(json string) { - srv.setReply("/a/changes/proj~master~I123456789", gerritReply{body: ")]}'\n" + json}) + srv.setReply("/a/changes/proj~main~I123456789", gerritReply{body: ")]}'\n" + json}) } t.Log("> submit with timeout") const submittedJSON = `{"status": "SUBMITTED", "mergeable": true, "labels": {"Code-Review": {"approved": {}}}}` setJSON(submittedJSON) - srv.setReply("/a/changes/proj~master~I123456789/submit", gerritReply{body: ")]}'\n" + submittedJSON}) + srv.setReply("/a/changes/proj~main~I123456789/submit", gerritReply{body: ")]}'\n" + submittedJSON}) testMainDied(t, "submit") - testRan(t, "git push -q origin HEAD:refs/for/master") + testRan(t, "git push -q origin HEAD:refs/for/main") testPrintedStderr(t, "cannot submit: timed out waiting for change to be submitted by Gerrit") } @@ -144,7 +144,7 @@ func TestSubmit(t *testing.T) { ) submitted := false npoll := 0 - srv.setReply("/a/changes/proj~master~I123456789", gerritReply{f: func() gerritReply { + srv.setReply("/a/changes/proj~main~I123456789", gerritReply{f: func() gerritReply { if !submitted { return gerritReply{body: ")]}'\n" + newJSON} } @@ -153,7 +153,7 @@ func TestSubmit(t *testing.T) { } return gerritReply{body: ")]}'\n" + mergedJSON} }}) - srv.setReply("/a/changes/proj~master~I123456789/submit", gerritReply{f: func() gerritReply { + srv.setReply("/a/changes/proj~main~I123456789/submit", gerritReply{f: func() gerritReply { if submitted { return gerritReply{status: 409} } @@ -235,20 +235,20 @@ func testSubmitMultiple(t *testing.T, gt *gitTest, srv *gerritServer) (*GerritCh Labels: map[string]*GerritLabel{"Code-Review": &GerritLabel{Approved: new(GerritAccount)}}, } - srv.setReply("/a/changes/proj~master~I0000001", gerritReply{f: func() gerritReply { + srv.setReply("/a/changes/proj~main~I0000001", gerritReply{f: func() gerritReply { return gerritReply{json: cl1} }}) - srv.setReply("/a/changes/proj~master~I0000001/submit", gerritReply{f: func() gerritReply { + srv.setReply("/a/changes/proj~main~I0000001/submit", gerritReply{f: func() gerritReply { if cl1.Status != "NEW" { return gerritReply{status: 409} } cl1.Status = "MERGED" return gerritReply{json: cl1} }}) - srv.setReply("/a/changes/proj~master~I0000002", gerritReply{f: func() gerritReply { + srv.setReply("/a/changes/proj~main~I0000002", gerritReply{f: func() gerritReply { return gerritReply{json: cl2} }}) - srv.setReply("/a/changes/proj~master~I0000002/submit", gerritReply{f: func() gerritReply { + srv.setReply("/a/changes/proj~main~I0000002/submit", gerritReply{f: func() gerritReply { if cl2.Status != "NEW" { return gerritReply{status: 409} } diff --git a/git-codereview/util_test.go b/git-codereview/util_test.go index 8acdb66..90a5b93 100644 --- a/git-codereview/util_test.go +++ b/git-codereview/util_test.go @@ -83,7 +83,7 @@ func (gt *gitTest) work(t *testing.T) { t.Helper() if gt.nwork == 0 { trun(t, gt.client, "git", "checkout", "-b", "work") - trun(t, gt.client, "git", "branch", "--set-upstream-to", "origin/master") + trun(t, gt.client, "git", "branch", "--set-upstream-to", "origin/main") trun(t, gt.client, "git", "tag", "work") // make sure commands do the right thing when there is a tag of the same name } @@ -142,22 +142,35 @@ func newGitTest(t *testing.T) (gt *gitTest) { server := tmpdir + "/git-origin" mkdir(t, server) - write(t, server+"/file", "this is master", 0644) + write(t, server+"/file", "this is main", 0644) write(t, server+"/.gitattributes", "* -text\n", 0644) trun(t, server, "git", "init", ".") trun(t, server, "git", "config", "user.name", "gopher") trun(t, server, "git", "config", "user.email", "gopher@example.com") trun(t, server, "git", "add", "file", ".gitattributes") - trun(t, server, "git", "commit", "-m", "on master") + trun(t, server, "git", "commit", "-m", "initial commit") + + // Newer gits use a default branch name of main. + // Older ones used master. + // So the branch name now may be main or master. + // We would like to assume main for the tests. + // Newer gits would let us do + // git init --initial-branch=main . + // above, but older gits don't have initial-branch. + // And we don't trust older gits to handle a no-op branch rename. + // So rename it to something different, and then to main. + // Then we'll be in a known state. + trun(t, server, "git", "branch", "-M", "certainly-not-main") + trun(t, server, "git", "branch", "-M", "main") for _, name := range []string{"dev.branch", "release.branch"} { - trun(t, server, "git", "checkout", "master") + trun(t, server, "git", "checkout", "main") trun(t, server, "git", "checkout", "-b", name) write(t, server+"/file."+name, "this is "+name, 0644) trun(t, server, "git", "add", "file."+name) trun(t, server, "git", "commit", "-m", "on "+name) } - trun(t, server, "git", "checkout", "master") + trun(t, server, "git", "checkout", "main") client := tmpdir + "/git-client" mkdir(t, client) @@ -439,7 +452,7 @@ func (s *gerritServer) setReply(path string, reply gerritReply) { } func (s *gerritServer) setJSON(id, json string) { - s.setReply("/a/changes/proj~master~"+id, gerritReply{body: ")]}'\n" + json}) + s.setReply("/a/changes/proj~main~"+id, gerritReply{body: ")]}'\n" + json}) } func (s *gerritServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { |
