Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/entire/cli/strategy/push_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func tryPushSessionsCommon(ctx context.Context, remoteName, branchName string) (
ctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
defer cancel()

result, err := remote.Push(ctx, remoteName, branchName)
result, err := remote.Push(ctx, remoteName, branchPushRefSpec(branchName))
outputStr := result.Output
if err != nil {
return pushResult{}, classifyPushFailure(ctx, outputStr, err)
Expand All @@ -220,6 +220,11 @@ func tryPushSessionsCommon(ctx context.Context, remoteName, branchName string) (
return parsePushResult(outputStr), nil
}

func branchPushRefSpec(branchName string) string {
branchRef := plumbing.NewBranchReferenceName(branchName).String()
return branchRef + ":" + branchRef
}

// protectedRefError means the remote is blocking writes to the ref itself.
type protectedRefError struct {
output string
Expand Down
43 changes: 43 additions & 0 deletions cmd/entire/cli/strategy/push_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,49 @@ func TestDoPushBranch_NewContent_SaysDone(t *testing.T) {
assert.NotContains(t, output, "already up-to-date", "should not say 'already up-to-date' when content was pushed")
}

// TestDoPushBranch_AmbiguousLocalRefs verifies that checkpoint pushes qualify
// the branch refspec. A stale refs/entire/checkpoints/v1 ref can otherwise make
// git reject the unqualified source ref as ambiguous.
//
// Not parallel: uses t.Chdir() and os.Stderr redirection.
func TestDoPushBranch_AmbiguousLocalRefs(t *testing.T) {
workDir := setupRepoWithCheckpointBranch(t)

headCmd := exec.CommandContext(context.Background(), "git", "rev-parse", "HEAD")
headCmd.Dir = workDir
headCmd.Env = testutil.GitIsolatedEnv()
headOut, err := headCmd.Output()
require.NoError(t, err)

staleRefCmd := exec.CommandContext(
context.Background(),
"git",
"update-ref",
"refs/entire/checkpoints/v1",
strings.TrimSpace(string(headOut)),
)
staleRefCmd.Dir = workDir
staleRefCmd.Env = testutil.GitIsolatedEnv()
out, err := staleRefCmd.CombinedOutput()
require.NoError(t, err, "stale ref setup failed: %s", out)

bareDir := t.TempDir()
initCmd := exec.CommandContext(context.Background(), "git", "init", "--bare")
initCmd.Dir = bareDir
initCmd.Env = testutil.GitIsolatedEnv()
out, err = initCmd.CombinedOutput()
require.NoError(t, err, "git init --bare failed: %s", out)

t.Chdir(workDir)

restore := captureStderr(t)
err = doPushBranch(context.Background(), bareDir, paths.MetadataBranchName)
output := restore()

require.NoError(t, err)
assert.Contains(t, output, " done", "should push despite ambiguous local refs")
}

func TestIsProtectedRefRejection(t *testing.T) {
t.Parallel()

Expand Down
Loading
Loading