MCPcopy Create free account
hub / github.com/cli/cli / TestClientPullRejectsNonFastForwardUpdate

Function TestClientPullRejectsNonFastForwardUpdate

git/client_test.go:1280–1306  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1278}
1279
1280func TestClientPullRejectsNonFastForwardUpdate(t *testing.T) {
1281 // Given local and remote trunk branches that have diverged
1282 source := newTestRepo(t)
1283 remote := newBareTestRepo(t)
1284 source.commit(t, "initial commit")
1285 source.run(t, "remote", "add", "origin", remote.fileURL())
1286 source.run(t, "push", "--quiet", "origin", "trunk")
1287 destination := newTestRepo(t)
1288 destination.run(t, "remote", "add", "origin", remote.fileURL())
1289 destination.run(t, "fetch", "--quiet", "origin", "trunk")
1290 destination.run(t, "reset", "--quiet", "--hard", "origin/trunk")
1291 localHead := destination.commit(t, "local update")
1292 source.commit(t, "remote update")
1293 source.run(t, "push", "--quiet", "origin", "trunk")
1294 destination.run(t, "config", "pull.rebase", "false")
1295
1296 // When the remote branch is pulled
1297 err := destination.client.Pull(t.Context(), "origin", "trunk")
1298
1299 // Then the fast-forward-only pull fails without merging either branch
1300 require.Error(t, err)
1301 var gitErr *GitError
1302 require.ErrorAs(t, err, &gitErr)
1303 assert.NotZero(t, gitErr.ExitCode)
1304 assert.Equal(t, localHead, destination.run(t, "rev-parse", "HEAD"))
1305 assert.Equal(t, "2", destination.run(t, "rev-list", "--count", "HEAD"))
1306}
1307
1308func TestClientPullUsesAuthenticatedFastForwardOnlyCommand(t *testing.T) {
1309 // Given a client that records the Git command

Callers

nothing calls this directly

Calls 8

newTestRepoFunction · 0.85
newBareTestRepoFunction · 0.85
commitMethod · 0.80
fileURLMethod · 0.80
EqualMethod · 0.80
PullMethod · 0.65
runMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected