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

Function TestClientPullFastForwardsCurrentBranch

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

Source from the content-addressed store, hash-verified

1251}
1252
1253func TestClientPullFastForwardsCurrentBranch(t *testing.T) {
1254 // Given a local branch behind its remote and a client defaulting to a different repository
1255 source := newTestRepo(t)
1256 remote := newBareTestRepo(t)
1257 source.commit(t, "initial commit")
1258 source.run(t, "remote", "add", "origin", remote.fileURL())
1259 source.run(t, "push", "--quiet", "origin", "trunk")
1260 destination := newTestRepo(t)
1261 destination.run(t, "remote", "add", "origin", remote.fileURL())
1262 destination.run(t, "fetch", "--quiet", "origin", "trunk")
1263 destination.run(t, "reset", "--quiet", "--hard", "origin/trunk")
1264 wantHead := source.commit(t, "remote update")
1265 source.run(t, "push", "--quiet", "origin", "trunk")
1266 defaultRepo := newTestRepo(t)
1267 defaultHead := defaultRepo.commit(t, "default repository commit")
1268 client := &Client{RepoDir: defaultRepo.dir}
1269
1270 // When the remote branch is pulled using a repository-directory modifier
1271 err := client.Pull(t.Context(), "origin", "trunk", WithRepoDir(destination.dir))
1272
1273 // Then only the destination branch fast-forwards to the remote commit
1274 require.NoError(t, err)
1275 assert.Equal(t, wantHead, destination.run(t, "rev-parse", "HEAD"))
1276 assert.Equal(t, wantHead, destination.run(t, "rev-parse", "refs/remotes/origin/trunk"))
1277 assert.Equal(t, defaultHead, defaultRepo.run(t, "rev-parse", "HEAD"))
1278}
1279
1280func TestClientPullRejectsNonFastForwardUpdate(t *testing.T) {
1281 // Given local and remote trunk branches that have diverged

Callers

nothing calls this directly

Calls 8

PullMethod · 0.95
newTestRepoFunction · 0.85
newBareTestRepoFunction · 0.85
WithRepoDirFunction · 0.85
commitMethod · 0.80
fileURLMethod · 0.80
EqualMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected