Skip to content

Commit 174e26e

Browse files
committed
Fix tests
1 parent 2c4a662 commit 174e26e

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

pkg/cmd/repo/sync/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func syncRemoteRepo(opts *SyncOptions) error {
215215
opts.IO.StopProgressIndicator()
216216
if err != nil {
217217
if errors.Is(err, divergingError) {
218-
return fmt.Errorf("can't sync because there are diverging changes, you can use `--force` to overwrite the changes")
218+
return fmt.Errorf("can't sync because there are diverging changes; use `--force` to overwrite the destination branch")
219219
}
220220
return err
221221
}

pkg/cmd/repo/sync/sync_test.go

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ func Test_SyncRun(t *testing.T) {
123123
},
124124
gitStubs: func(mgc *mockGitClient) {
125125
mgc.On("IsDirty").Return(false, nil).Once()
126-
mgc.On("Fetch", []string{"origin", "+refs/heads/trunk"}).Return(nil).Once()
127-
mgc.On("HasLocalBranch", []string{"trunk"}).Return(true).Once()
126+
mgc.On("Fetch", "origin", "refs/heads/trunk").Return(nil).Once()
127+
mgc.On("HasLocalBranch", "trunk").Return(true).Once()
128128
mgc.On("BranchRemote", "trunk").Return("origin", nil).Once()
129-
mgc.On("IsAncestor", []string{"trunk", "origin/trunk"}).Return(true, nil).Once()
129+
mgc.On("IsAncestor", "trunk", "origin/trunk").Return(true, nil).Once()
130130
mgc.On("CurrentBranch").Return("trunk", nil).Once()
131-
mgc.On("Merge", []string{"--ff-only", "refs/remotes/origin/trunk"}).Return(nil).Once()
131+
mgc.On("MergeFastForward", "refs/remotes/origin/trunk").Return(nil).Once()
132132
},
133-
wantStdout: "✓ Synced .:trunk from OWNER/REPO:trunk\n",
133+
wantStdout: "✓ Synced the \"trunk\" branch from OWNER/REPO to local repository\n",
134134
},
135135
{
136136
name: "sync local repo with parent - notty",
@@ -143,12 +143,12 @@ func Test_SyncRun(t *testing.T) {
143143
},
144144
gitStubs: func(mgc *mockGitClient) {
145145
mgc.On("IsDirty").Return(false, nil).Once()
146-
mgc.On("Fetch", []string{"origin", "+refs/heads/trunk"}).Return(nil).Once()
147-
mgc.On("HasLocalBranch", []string{"trunk"}).Return(true).Once()
146+
mgc.On("Fetch", "origin", "refs/heads/trunk").Return(nil).Once()
147+
mgc.On("HasLocalBranch", "trunk").Return(true).Once()
148148
mgc.On("BranchRemote", "trunk").Return("origin", nil).Once()
149-
mgc.On("IsAncestor", []string{"trunk", "origin/trunk"}).Return(true, nil).Once()
149+
mgc.On("IsAncestor", "trunk", "origin/trunk").Return(true, nil).Once()
150150
mgc.On("CurrentBranch").Return("trunk", nil).Once()
151-
mgc.On("Merge", []string{"--ff-only", "refs/remotes/origin/trunk"}).Return(nil).Once()
151+
mgc.On("MergeFastForward", "refs/remotes/origin/trunk").Return(nil).Once()
152152
},
153153
wantStdout: "",
154154
},
@@ -165,14 +165,14 @@ func Test_SyncRun(t *testing.T) {
165165
},
166166
gitStubs: func(mgc *mockGitClient) {
167167
mgc.On("IsDirty").Return(false, nil).Once()
168-
mgc.On("Fetch", []string{"upstream", "+refs/heads/trunk"}).Return(nil).Once()
169-
mgc.On("HasLocalBranch", []string{"trunk"}).Return(true).Once()
168+
mgc.On("Fetch", "upstream", "refs/heads/trunk").Return(nil).Once()
169+
mgc.On("HasLocalBranch", "trunk").Return(true).Once()
170170
mgc.On("BranchRemote", "trunk").Return("upstream", nil).Once()
171-
mgc.On("IsAncestor", []string{"trunk", "upstream/trunk"}).Return(true, nil).Once()
171+
mgc.On("IsAncestor", "trunk", "upstream/trunk").Return(true, nil).Once()
172172
mgc.On("CurrentBranch").Return("trunk", nil).Once()
173-
mgc.On("Merge", []string{"--ff-only", "refs/remotes/upstream/trunk"}).Return(nil).Once()
173+
mgc.On("MergeFastForward", "refs/remotes/upstream/trunk").Return(nil).Once()
174174
},
175-
wantStdout: "✓ Synced .:trunk from OWNER2/REPO2:trunk\n",
175+
wantStdout: "✓ Synced the \"trunk\" branch from OWNER2/REPO2 to local repository\n",
176176
},
177177
{
178178
name: "sync local repo with parent and specified branch",
@@ -182,14 +182,14 @@ func Test_SyncRun(t *testing.T) {
182182
},
183183
gitStubs: func(mgc *mockGitClient) {
184184
mgc.On("IsDirty").Return(false, nil).Once()
185-
mgc.On("Fetch", []string{"origin", "+refs/heads/test"}).Return(nil).Once()
186-
mgc.On("HasLocalBranch", []string{"test"}).Return(true).Once()
185+
mgc.On("Fetch", "origin", "refs/heads/test").Return(nil).Once()
186+
mgc.On("HasLocalBranch", "test").Return(true).Once()
187187
mgc.On("BranchRemote", "test").Return("origin", nil).Once()
188-
mgc.On("IsAncestor", []string{"test", "origin/test"}).Return(true, nil).Once()
188+
mgc.On("IsAncestor", "test", "origin/test").Return(true, nil).Once()
189189
mgc.On("CurrentBranch").Return("test", nil).Once()
190-
mgc.On("Merge", []string{"--ff-only", "refs/remotes/origin/test"}).Return(nil).Once()
190+
mgc.On("MergeFastForward", "refs/remotes/origin/test").Return(nil).Once()
191191
},
192-
wantStdout: "✓ Synced .:test from OWNER/REPO:test\n",
192+
wantStdout: "✓ Synced the \"test\" branch from OWNER/REPO to local repository\n",
193193
},
194194
{
195195
name: "sync local repo with parent and force specified",
@@ -204,14 +204,14 @@ func Test_SyncRun(t *testing.T) {
204204
},
205205
gitStubs: func(mgc *mockGitClient) {
206206
mgc.On("IsDirty").Return(false, nil).Once()
207-
mgc.On("Fetch", []string{"origin", "+refs/heads/trunk"}).Return(nil).Once()
208-
mgc.On("HasLocalBranch", []string{"trunk"}).Return(true).Once()
207+
mgc.On("Fetch", "origin", "refs/heads/trunk").Return(nil).Once()
208+
mgc.On("HasLocalBranch", "trunk").Return(true).Once()
209209
mgc.On("BranchRemote", "trunk").Return("origin", nil).Once()
210-
mgc.On("IsAncestor", []string{"trunk", "origin/trunk"}).Return(false, nil).Once()
210+
mgc.On("IsAncestor", "trunk", "origin/trunk").Return(false, nil).Once()
211211
mgc.On("CurrentBranch").Return("trunk", nil).Once()
212-
mgc.On("Reset", []string{"--hard", "refs/remotes/origin/trunk"}).Return(nil).Once()
212+
mgc.On("ResetHard", "refs/remotes/origin/trunk").Return(nil).Once()
213213
},
214-
wantStdout: "✓ Synced .:trunk from OWNER/REPO:trunk\n",
214+
wantStdout: "✓ Synced the \"trunk\" branch from OWNER/REPO to local repository\n",
215215
},
216216
{
217217
name: "sync local repo with parent and not fast forward merge",
@@ -224,13 +224,13 @@ func Test_SyncRun(t *testing.T) {
224224
},
225225
gitStubs: func(mgc *mockGitClient) {
226226
mgc.On("IsDirty").Return(false, nil).Once()
227-
mgc.On("Fetch", []string{"origin", "+refs/heads/trunk"}).Return(nil).Once()
228-
mgc.On("HasLocalBranch", []string{"trunk"}).Return(true).Once()
227+
mgc.On("Fetch", "origin", "refs/heads/trunk").Return(nil).Once()
228+
mgc.On("HasLocalBranch", "trunk").Return(true).Once()
229229
mgc.On("BranchRemote", "trunk").Return("origin", nil).Once()
230-
mgc.On("IsAncestor", []string{"trunk", "origin/trunk"}).Return(false, nil).Once()
230+
mgc.On("IsAncestor", "trunk", "origin/trunk").Return(false, nil).Once()
231231
},
232232
wantErr: true,
233-
errMsg: "can't sync because there are diverging changes, you can use `--force` to overwrite the changes",
233+
errMsg: "can't sync because there are diverging changes; use `--force` to overwrite the destination branch",
234234
},
235235
{
236236
name: "sync local repo with parent and mismatching branch remotes",
@@ -243,8 +243,8 @@ func Test_SyncRun(t *testing.T) {
243243
},
244244
gitStubs: func(mgc *mockGitClient) {
245245
mgc.On("IsDirty").Return(false, nil).Once()
246-
mgc.On("Fetch", []string{"origin", "+refs/heads/trunk"}).Return(nil).Once()
247-
mgc.On("HasLocalBranch", []string{"trunk"}).Return(true).Once()
246+
mgc.On("Fetch", "origin", "refs/heads/trunk").Return(nil).Once()
247+
mgc.On("HasLocalBranch", "trunk").Return(true).Once()
248248
mgc.On("BranchRemote", "trunk").Return("upstream", nil).Once()
249249
},
250250
wantErr: true,
@@ -271,16 +271,16 @@ func Test_SyncRun(t *testing.T) {
271271
},
272272
gitStubs: func(mgc *mockGitClient) {
273273
mgc.On("IsDirty").Return(false, nil).Once()
274-
mgc.On("Fetch", []string{"origin", "+refs/heads/trunk"}).Return(nil).Once()
275-
mgc.On("HasLocalBranch", []string{"trunk"}).Return(true).Once()
274+
mgc.On("Fetch", "origin", "refs/heads/trunk").Return(nil).Once()
275+
mgc.On("HasLocalBranch", "trunk").Return(true).Once()
276276
mgc.On("BranchRemote", "trunk").Return("origin", nil).Once()
277-
mgc.On("IsAncestor", []string{"trunk", "origin/trunk"}).Return(true, nil).Once()
277+
mgc.On("IsAncestor", "trunk", "origin/trunk").Return(true, nil).Once()
278278
mgc.On("CurrentBranch").Return("test", nil).Once()
279-
mgc.On("Checkout", []string{"trunk"}).Return(nil).Once()
280-
mgc.On("Merge", []string{"--ff-only", "refs/remotes/origin/trunk"}).Return(nil).Once()
281-
mgc.On("Checkout", []string{"test"}).Return(nil).Once()
279+
mgc.On("CheckoutLocal", "trunk").Return(nil).Once()
280+
mgc.On("MergeFastForward", "refs/remotes/origin/trunk").Return(nil).Once()
281+
mgc.On("CheckoutLocal", "test").Return(nil).Once()
282282
},
283-
wantStdout: "✓ Synced .:trunk from OWNER/REPO:trunk\n",
283+
wantStdout: "✓ Synced the \"trunk\" branch from OWNER/REPO to local repository\n",
284284
},
285285
{
286286
name: "sync remote fork with parent - tty",
@@ -302,7 +302,7 @@ func Test_SyncRun(t *testing.T) {
302302
httpmock.REST("PATCH", "repos/OWNER/REPO-FORK/git/refs/heads/trunk"),
303303
httpmock.StringResponse(`{}`))
304304
},
305-
wantStdout: "✓ Synced OWNER/REPO-FORK:trunk from OWNER/REPO:trunk\n",
305+
wantStdout: "✓ Synced the \"trunk\" branch from OWNER/REPO to OWNER/REPO-FORK\n",
306306
},
307307
{
308308
name: "sync remote fork with parent - notty",
@@ -338,7 +338,7 @@ func Test_SyncRun(t *testing.T) {
338338
httpmock.StringResponse(`{"data":{"repository":{}}}`))
339339
},
340340
wantErr: true,
341-
errMsg: "can't determine source repo for OWNER/REPO because repo is not fork",
341+
errMsg: "can't determine source repository for OWNER/REPO because repository is not fork",
342342
},
343343
{
344344
name: "sync remote repo with specified source repo",
@@ -358,7 +358,7 @@ func Test_SyncRun(t *testing.T) {
358358
httpmock.REST("PATCH", "repos/OWNER/REPO/git/refs/heads/trunk"),
359359
httpmock.StringResponse(`{}`))
360360
},
361-
wantStdout: "✓ Synced OWNER/REPO:trunk from OWNER2/REPO2:trunk\n",
361+
wantStdout: "✓ Synced the \"trunk\" branch from OWNER2/REPO2 to OWNER/REPO\n",
362362
},
363363
{
364364
name: "sync remote fork with parent and specified branch",
@@ -378,7 +378,7 @@ func Test_SyncRun(t *testing.T) {
378378
httpmock.REST("PATCH", "repos/OWNER/REPO-FORK/git/refs/heads/test"),
379379
httpmock.StringResponse(`{}`))
380380
},
381-
wantStdout: "✓ Synced OWNER/REPO-FORK:test from OWNER/REPO:test\n",
381+
wantStdout: "✓ Synced the \"test\" branch from OWNER/REPO to OWNER/REPO-FORK\n",
382382
},
383383
{
384384
name: "sync remote fork with parent and force specified",
@@ -401,7 +401,7 @@ func Test_SyncRun(t *testing.T) {
401401
httpmock.REST("PATCH", "repos/OWNER/REPO-FORK/git/refs/heads/trunk"),
402402
httpmock.StringResponse(`{}`))
403403
},
404-
wantStdout: "✓ Synced OWNER/REPO-FORK:trunk from OWNER/REPO:trunk\n",
404+
wantStdout: "✓ Synced the \"trunk\" branch from OWNER/REPO to OWNER/REPO-FORK\n",
405405
},
406406
{
407407
name: "sync remote fork with parent and not fast forward merge",
@@ -431,7 +431,7 @@ func Test_SyncRun(t *testing.T) {
431431
})
432432
},
433433
wantErr: true,
434-
errMsg: "can't sync because there are diverging changes, you can use `--force` to overwrite the changes",
434+
errMsg: "can't sync because there are diverging changes; use `--force` to overwrite the destination branch",
435435
},
436436
}
437437
for _, tt := range tests {

0 commit comments

Comments
 (0)