Merge pull request #1733 from entireio/paul/skip-fetch-all · Entire
Merge pull request #1733 from entireio/paul/skip-fetch-all
04eabf7→main·
Exclude URL-keyed promisor entries from git fetch --all
Changes
3
cmd/entire/cli
- checkpoint/remote
Mgit.go+68/-1
Mgit_test.go+133
integration_test
Mtestenv.go+12/-5
3 unmodified lines
4
5
6
7
8
9
10
1 unmodified line
12
13
14
15
16
17
18
59 unmodified lines
78
79
80
79
81
82
83
84
85
8 unmodified lines
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
3 unmodified lines
"context"
"encoding/base64"
"fmt"
"log/slog"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
"github.com/entireio/cli/cmd/entire/cli/logging"
"github.com/entireio/cli/cmd/entire/cli/settings"
59 unmodified lines
case opts.Unshallow && isShallowRepository(ctx, opts.Dir): args = append(args, "--unshallow") } if !opts.NoFilter && settings.IsFilteredFetchesEnabled(ctx) { filtered := !opts.NoFilter && settings.IsFilteredFetchesEnabled(ctx) if filtered { args = append(args, "--filter=blob:none") } args = append(args, opts.Remote)
if err != nil { return out, fmt.Errorf("git fetch: %w", err) } if filtered && IsURL(opts.Remote) { // Stamp the URL git actually fetched from: with a checkpoint token set, // newCommand rewrites SSH targets to HTTPS, and git records the // promisor entry under the rewritten URL. target := opts.Remote if token := strings.TrimSpace(os.Getenv(CheckpointTokenEnvVar)); token != "" && isValidToken(token) { target, _ = resolveTargetForTokenAuth(ctx, target) } markPromisorEntrySkipped(ctx, opts.Dir, target) } return out, nil }
// markPromisorEntrySkipped excludes the URL-keyed config section that git
// creates for a filtered URL fetch (remote.git fetch --all and git remote update. Git needs the promisor entry to
// lazy-fetch filtered-out objects later, but the entry also makes the URL show
// up as a fetchable remote, so without this every checkpoint URL ever fetched
// from lingers as a phantom remote that bulk fetches keep dialing.
// Best-effort: the fetch already succeeded, so failures only log.
func markPromisorEntrySkipped(ctx context.Context, dir, url string) {
if !gitConfigBool(ctx, dir, "remote."+url+".promisor") {
// Git didn't record a promisor entry for this URL; don't invent a
// config section that wouldn't otherwise exist.
return
}
for _, key := range []string{"skipFetchAll", "skipDefaultUpdate"} {
fullKey := "remote." + url + "." + key
if gitConfigBool(ctx, dir, fullKey) {
// Checked per key so a partially-stamped entry (e.g. an earlier
// run failing between the two writes) still gets completed.
continue
}
cmd := exec.CommandContext(ctx, "git", "config", "--local", fullKey, "true")
if dir != "" {
cmd.Dir = dir
}
if out, cfgErr := cmd.CombinedOutput(); cfgErr != nil {
redactedURL := RedactURL(url)
// The output can echo the key, which embeds the URL — and a URL
// can carry credentials. Redact before logging.
msg := strings.TrimSpace(strings.ReplaceAll(string(out), url, redactedURL))
logging.Warn(ctx, "failed to mark promisor config entry as skipped for bulk fetches",
slog.String("url", redactedURL),
slog.String("key", key),
slog.String("output", msg),
slog.String("error", cfgErr.Error()),
)
return
}
}
}
// gitConfigBool reads a local git config key and reports whether it is set to // a true value. Missing keys and read errors report false. func gitConfigBool(ctx context.Context, dir, key string) bool { cmd := exec.CommandContext(ctx, "git", "config", "--local", "--get", "--type=bool", key) if dir != "" { cmd.Dir = dir } out, err := cmd.Output() if err != nil { return false } return strings.TrimSpace(string(out)) == "true" }
// FetchBlobs fetches specific objects (typically blobs) by hash from a remote.
// Uses git fetch-pack rather than git fetch because the high-level
// porcelain enforces partial-clone integrity checks that reject blob-only