(t *testing.T)
| 1251 | } |
| 1252 | |
| 1253 | func 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 | |
| 1280 | func TestClientPullRejectsNonFastForwardUpdate(t *testing.T) { |
| 1281 | // Given local and remote trunk branches that have diverged |
nothing calls this directly
no test coverage detected