Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

Count no pushed commits for an unbounded push to a URL

Claude9118d1d47094
diff --git a/cli/beacon/internal/gitlink/share.go b/cli/beacon/internal/gitlink/share.go
index 20ccb8f3..cddc7792 100644
--- a/cli/beacon/internal/gitlink/share.go
+++ b/cli/beacon/internal/gitlink/share.go
@@ -315,8 +315,9 @@ func SetShareSessions(ctx context.Context, repo Repo, enabled bool, visibility s
// PushedCommits lists the commits a pre-push hook's stdin says are being pushed: for each
// `<local-ref> <local-sha> <remote-ref> <remote-sha>` line, the commits reachable from the local
// sha and not from the remote sha (or, for a new remote branch or a remote sha this clone does not
-// have, from any of the remote's tracking branches when remote is a configured remote). Deletions
-// push nothing. At most limit commits, newest first.
+// have, from any of the remote's tracking branches when remote is a configured remote; pushed to a
+// URL, such a line counts no commits, since nothing would bound it). Deletions push nothing. At
+// most limit commits, newest first.
func PushedCommits(ctx context.Context, repo Repo, remote string, stdin string, limit int) ([]string, error) {
if limit <= 0 {
limit = 100
@@ -337,6 +338,10 @@ func PushedCommits(ctx context.Context, repo Repo, remote string, stdin string,
// A new remote branch, or a force push over commits this clone never fetched: the
// remote's tip is not here to exclude, so exclude everything already on the remote.
args = append(args, "--remotes="+remote)
+ default:
+ // A push to a URL with nothing here to exclude: every ancestor would count as pushed,
+ // including commits the remote has had for years. Count none rather than guess.
+ continue
}
list, err := repo.Git.Run(ctx, nil, args...)
if err != nil {
diff --git a/cli/beacon/internal/gitlink/share_test.go b/cli/beacon/internal/gitlink/share_test.go
index 95d83f0d..628f5980 100644
--- a/cli/beacon/internal/gitlink/share_test.go
+++ b/cli/beacon/internal/gitlink/share_test.go
@@ -384,3 +384,28 @@ func TestPushedCommitsForcePushOverUnfetchedRemoteTip(t *testing.T) {
t.Fatalf("pushed %v, want [%s]", got, mine)
}
}
+
+// A push to a URL (not a configured remote) with nothing here to exclude counts no commits,
+// rather than every ancestor of the pushed sha.
+func TestPushedCommitsToAURLWithoutABoundCountsNothing(t *testing.T) {
+ tm := newTeam(t)
+ ctx := context.Background()
+ tm.alice.write("f", "2")
+ second := tm.alice.commitAt("second", t0.Add(time.Minute))
+ alice := tm.alice.open()
+ zero := strings.Repeat("0", len(second))
+ got, err := PushedCommits(ctx, alice, tm.remote, "HEAD "+second+" refs/heads/new "+zero+"\n", 0)
+ if err != nil || len(got) != 0 {
+ t.Fatalf("new branch pushed to a URL: %v %v, want none", got, err)
+ }
+ missing := strings.Repeat("ab", len(second)/2)
+ got, err = PushedCommits(ctx, alice, tm.remote, "HEAD "+second+" refs/heads/main "+missing+"\n", 0)
+ if err != nil || len(got) != 0 {
+ t.Fatalf("force push to a URL over an unknown tip: %v %v, want none", got, err)
+ }
+ // A known remote sha still bounds a push to a URL.
+ got, err = PushedCommits(ctx, alice, tm.remote, "HEAD "+second+" refs/heads/main "+tm.first+"\n", 0)
+ if err != nil || !reflect.DeepEqual(got, []string{second}) {
+ t.Fatalf("push to a URL over a known tip: %v %v", got, err)
+ }
+}