GitLabgitlab-org
cli
main
1package checkout
3import (
4 "context"
5 "fmt"
6 "path/filepath"
7 "strings"
8 "unicode"
10 "github.com/MakeNowJust/heredoc/v2"
11 "github.com/spf13/cobra"
13 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
15 "gitlab.com/gitlab-org/cli/internal/api"
16 "gitlab.com/gitlab-org/cli/internal/cmdutils"
17 "gitlab.com/gitlab-org/cli/internal/commands/mr/mrutils"
18 "gitlab.com/gitlab-org/cli/internal/config"
19 "gitlab.com/gitlab-org/cli/internal/dbg"
20 "gitlab.com/gitlab-org/cli/internal/git"
21 "gitlab.com/gitlab-org/cli/internal/glrepo"
22 "gitlab.com/gitlab-org/cli/internal/iostreams"
23 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
24)
26type options struct {
27 // flag values
28 branch string
29 track bool
30 upstream string
31 force bool
32 worktree string
34 // dependencies captured from factory
35 factory cmdutils.Factory
36 io *iostreams.IOStreams
37 gr git.GitRunner
38 gitlabClient func() (*gitlab.Client, error)
39 remotes func() (glrepo.Remotes, error)
40 config func() config.Config
42 // resolved by complete before invoking run
43 mr *gitlab.MergeRequest
44 baseRepo glrepo.Interface
46 // set by validate() when --worktree already points at this branch's worktree
47 worktreeInPlace bool
48}
50func NewCmdCheckout(f cmdutils.Factory) *cobra.Command {
51 opts := &options{
52 factory: f,
53 io: f.IO(),
54 gr: f.GitRunner(),
55 gitlabClient: f.GitLabClient,
56 remotes: f.Remotes,
57 config: f.Config,
58 }
60 cmd := &cobra.Command{
61 Use: "checkout [<id> | <branch> | <url>]",
62 Short: "Check out an open merge request.",
63 Long: heredoc.Docf(`
64 Defaults to the currently checked-out branch. Use %[1]s--branch%[1]s to
65 override the local branch name used for the checkout.
67 Use %[1]s--worktree%[1]s to check out the merge request into a Git worktree at the given path. Your current working directory and any work in progress stay untouched. If you run the command again with the same path, it updates the existing worktree.
69 You can only check out a branch in one worktree at a time. If a branch is already checked out elsewhere, use %[1]s--branch%[1]s to check it out under a different name.
71 To remove the worktree when you are done, run %[1]sgit worktree remove <path>%[1]s.
72 `, "`"),
73 Example: heredoc.Doc(`
74 glab mr checkout 1
75 glab mr checkout branch
76 glab mr checkout 12 --branch todo-fix
77 glab mr checkout new-feature --set-upstream-to=upstream/main
78 glab mr checkout https://gitlab.com/gitlab-org/cli/-/merge_requests/1234
80 # Check out into a separate worktree
81 glab mr checkout 123 --worktree ../review-mr-123
83 # Uses the checked-out branch
84 glab mr checkout`),
85 Args: cobra.ExactArgs(1),
86 Annotations: map[string]string{
87 mcpannotations.Destructive: "true",
88 },
89 RunE: func(cmd *cobra.Command, args []string) error {
90 ctx := cmd.Context()
91 if err := opts.complete(ctx, args); err != nil {
92 return err
93 }
94 if err := opts.validate(); err != nil {
95 return err
96 }
97 return opts.run(ctx)
98 },
99 }
101 fl := cmd.Flags()
102 fl.StringVarP(&opts.branch, "branch", "b", "", "Check out merge request with name <branch>.")
103 fl.BoolVarP(&opts.track, "track", "t", true, "Set checked out branch to track the remote branch.")
104 _ = fl.MarkDeprecated("track", "Now enabled by default")
105 fl.StringVarP(&opts.upstream, "set-upstream-to", "u", "", "Set tracking of checked-out branch to [REMOTE/]BRANCH.")
106 fl.BoolVarP(&opts.force, "force", "f", false, "Reset local branch to remote when they have diverged. Refuses if working tree has changes that would be lost.")
107 fl.StringVar(&opts.worktree, "worktree", "", "Check out the merge request into a Git worktree at <path> instead of the current working directory. Re-running updates an existing worktree at that path.")
108 return cmd
109}
111func (o *options) complete(ctx context.Context, args []string) error {
112 mr, baseRepo, err := mrutils.MRFromArgs(ctx, o.factory, args, "any")
113 if err != nil {
114 return err
115 }
116 if mr.SHA == "" {
117 return fmt.Errorf("merge request !%d has no head commit", mr.IID)
118 }
119 o.mr = mr
120 o.baseRepo = baseRepo
122 if o.branch == "" {
123 o.branch = o.mr.SourceBranch
124 }
125 if err := validateBranchName(o.branch); err != nil {
126 return err
127 }
129 return nil
130}
132func validateBranchName(name string) error {
133 if name == "" || strings.HasPrefix(name, "-") || strings.ContainsFunc(name, func(r rune) bool {
134 return unicode.IsSpace(r) || unicode.IsControl(r)
135 }) {
136 return fmt.Errorf("invalid branch name %q", name)
137 }
138 return nil
139}
141func (o *options) validate() error {
142 if o.upstream != "" {
143 if val := strings.Split(o.upstream, "/"); len(val) > 1 {
144 // Verify that we have the remote set
145 repo, err := o.remotes()
146 if err != nil {
147 return err
148 }
149 _, err = repo.FindByName(val[0])
150 if err != nil {
151 return err
152 }
153 }
154 }
156 if o.worktree != "" {
157 existing, prunable, err := o.worktreeForBranch()
158 if err != nil {
159 return err
160 }
161 switch {
162 case existing == "":
163 case prunable:
164 return fmt.Errorf("branch %q is held by a worktree at %q whose directory is gone; run `git worktree prune`, then retry", o.branch, existing)
165 case sameWorktreePath(existing, o.worktree):
166 o.worktreeInPlace = true
167 default:
168 return fmt.Errorf("branch %q is already checked out at %q; use that worktree, or pass --branch to check it out under a different name", o.branch, existing)
169 }
170 }
172 return nil
173}
175// worktreeForBranch returns the path of the worktree that already has o.branch
176// checked out, and whether that worktree is prunable: still listed, but with its
177// directory gone. `git worktree add` refuses a branch that is checked out
178// anywhere, prunable or not, so this runs in validate() to fail before the fetch
179// and the config writes.
180func (o *options) worktreeForBranch() (string, bool, error) {
181 out, err := o.gr.Git("worktree", "list", "--porcelain")
182 if err != nil {
183 return "", false, err
184 }
186 // Blocks of `worktree <path>` / `HEAD <sha>` / `branch refs/heads/<name>`,
187 // with the branch line absent for a detached HEAD and a `prunable` line
188 // appended once the directory is gone. That line follows the branch line, so
189 // each block is only decided at the next `worktree` line or at the end.
190 var path string
191 var match, prunable bool
192 for line := range strings.SplitSeq(strings.TrimSpace(out), "\n") {
193 line = strings.TrimSpace(line)
194 switch {
195 case strings.HasPrefix(line, "worktree "):
196 if match {
197 return path, prunable, nil
198 }
199 path = strings.TrimPrefix(line, "worktree ")
200 match, prunable = false, false
201 case line == "branch refs/heads/"+o.branch:
202 match = true
203 case line == "prunable" || strings.HasPrefix(line, "prunable "):
204 prunable = true
205 }
206 }
207 if match {
208 return path, prunable, nil
209 }
210 return "", false, nil
211}
213// resolveWorktreePath makes a path comparable with the ones `git worktree list`
214// prints, which have their symlinks resolved. EvalSymlinks fails on a path that
215// does not exist yet, the ordinary first-run case, so fall back to the cleaned
216// absolute path.
217func resolveWorktreePath(p string) string {
218 abs, err := filepath.Abs(p)
219 if err != nil {
220 return filepath.Clean(p)
221 }
222 if resolved, err := filepath.EvalSymlinks(abs); err == nil {
223 return resolved
224 }
225 return filepath.Clean(abs)
226}
228// sameWorktreePath reports whether a path listed by git is the same place as the
229// --worktree argument. Both sides are resolved: git usually reports the resolved
230// path, but the reverse happens too.
231func sameWorktreePath(listed, requested string) bool {
232 return resolveWorktreePath(listed) == resolveWorktreePath(requested)
233}
235func (o *options) run(ctx context.Context) error {
236 if o.worktreeInPlace {
237 o.io.LogInfof("Branch %q is already checked out at %q, updating it there.\n", o.branch, o.worktree)
238 }
240 client, err := o.gitlabClient()
241 if err != nil {
242 return err
243 }
245 var mrRef string
246 var mrProject *gitlab.Project
248 mrProject, err = api.GetProject(client, o.mr.SourceProjectID)
249 if err != nil {
250 // If we don't have access to the source project, let's try the target project
251 mrProject, err = api.GetProject(client, o.mr.TargetProjectID)
252 if err != nil {
253 return err
254 }
256 // We found the target project, let's find the ref another way
257 mrRef = fmt.Sprintf("refs/merge-requests/%d/head", o.mr.IID)
258 } else {
259 mrRef = fmt.Sprintf("refs/heads/%s", o.mr.SourceBranch)
260 }
262 // Get the appropriate remote URL based on user's git_protocol preference
263 gitProtocol, err := o.config().Get(o.baseRepo.RepoHost(), "git_protocol")
264 if err != nil {
265 return err
266 }
267 fetchRemote, err := glrepo.RemoteURL(mrProject, gitProtocol)
268 if err != nil {
269 return err
270 }
272 // Git only writes refs/remotes/<remote>/<branch> when it fetches through a
273 // named remote, so a URL fetch leaves branch.<name>.remote with nothing for
274 // @{u} to resolve to.
275 if strings.HasPrefix(mrRef, "refs/heads/") {
276 if remoteName := o.matchingRemoteName(mrProject); remoteName != "" {
277 fetchRemote = remoteName
278 }
279 }
281 localSHA := o.localBranchSHA()
282 switch {
283 case localSHA == o.mr.SHA:
284 o.io.LogInfof("Branch %q already at merge request head, skipping fetch.\n", o.branch)
285 case localSHA == "" && o.mrHeadIsLocal():
286 if _, err := o.gr.Git("branch", o.branch, o.mr.SHA); err != nil {
287 return err
288 }
289 o.io.LogInfof("Created branch %q from local commit, skipping fetch.\n", o.branch)
290 default:
291 // git always refuses to fetch into a branch a worktree holds, so an in-place
292 // update goes straight to the fallback rather than printing that refusal on
293 // every re-run.
294 if o.worktreeInPlace {
295 if err := o.fetchRefOnly(ctx, fetchRemote, mrRef); err != nil {
296 return err
297 }
298 break
299 }
300 fetchRefSpec := fmt.Sprintf("%s:%s", mrRef, o.branch)
301 if err := o.gr.GitWithIO(o.io.StdOut, o.io.StdErr, "fetch", "--", fetchRemote, fetchRefSpec); err != nil {
302 // Remote diverged from local. Fall back to fetching just the ref (FETCH_HEAD only).
303 if err := o.fetchRefOnly(ctx, fetchRemote, mrRef); err != nil {
304 return err
305 }
306 }
307 }
309 // .remote is needed for `git pull` to work
310 // .pushRemote is needed for `git push` to work, if user has set `remote.pushDefault`.
311 // see https://git-scm.com/docs/git-config#Documentation/git-config.txt-branchltnamegtremote
312 if _, err := o.gr.Git("config", fmt.Sprintf("branch.%s.remote", o.branch), fetchRemote); err != nil {
313 return err
314 }
315 if o.mr.AllowCollaboration {
316 if _, err := o.gr.Git("config", fmt.Sprintf("branch.%s.pushRemote", o.branch), fetchRemote); err != nil {
317 return err
318 }
319 }
320 if _, err := o.gr.Git("config", fmt.Sprintf("branch.%s.merge", o.branch), mrRef); err != nil {
321 return err
322 }
324 switch {
325 case o.worktreeInPlace:
326 // Already checked out at o.worktree; resolveDivergence updated it.
327 case o.worktree != "":
328 if err := o.gr.GitWithIO(o.io.StdOut, o.io.StdErr, "worktree", "add", "--", o.worktree, o.branch); err != nil {
329 return fmt.Errorf("could not add worktree %q for branch %q: %w", o.worktree, o.branch, err)
330 }
331 default:
332 if err := o.gr.GitWithIO(o.io.StdOut, o.io.StdErr, "checkout", o.branch); err != nil {
333 return fmt.Errorf("could not checkout branch %q: %w", o.branch, err)
334 }
335 }
337 if o.upstream != "" {
338 // Name the branch explicitly: with --worktree it is not the current branch here.
339 if _, err := o.gr.Git("branch", "--set-upstream-to", o.upstream, o.branch); err != nil {
340 return err
341 }
342 }
343 return nil
344}
346// fetchRefOnly fetches the merge request ref without updating the local branch,
347// leaving the result in FETCH_HEAD for resolveDivergence to apply.
348func (o *options) fetchRefOnly(ctx context.Context, fetchRemote, mrRef string) error {
349 if err := o.gr.GitWithIO(o.io.StdOut, o.io.StdErr, "fetch", "--", fetchRemote, mrRef); err != nil {
350 return err
351 }
352 return o.resolveDivergence(ctx)
353}
355// localBranchSHA returns the commit refs/heads/<branch> points at, or "" when
356// the branch does not exist.
357func (o *options) localBranchSHA() string {
358 sha, err := o.gr.Git("rev-parse", "--verify", "refs/heads/"+o.branch)
359 if err != nil {
360 return ""
361 }
362 return strings.TrimSpace(sha)
363}
365// mrHeadIsLocal reports whether the merge request head commit is already in
366// the object store, so a branch can be created from it without fetching.
367func (o *options) mrHeadIsLocal() bool {
368 _, err := o.gr.Git("rev-parse", "--verify", o.mr.SHA+"^{commit}")
369 return err == nil
370}
372// matchingRemoteName returns the name of a locally configured git remote that
373// points at mrProject, or an empty string if none matches.
374func (o *options) matchingRemoteName(mrProject *gitlab.Project) string {
375 remotes, err := o.remotes()
376 if err != nil {
377 dbg.Debug("could not read git remotes:", err.Error())
378 return ""
379 }
380 mrRepo, err := glrepo.FromFullName(mrProject.PathWithNamespace, o.baseRepo.RepoHost(), o.config())
381 if err != nil {
382 dbg.Debug("could not resolve merge request project:", err.Error())
383 return ""
384 }
385 for _, remote := range remotes {
386 if glrepo.IsSame(remote.Repo, mrRepo) {
387 return remote.Name
388 }
389 }
390 return ""
391}
393// resolveDivergence is called after the fallback fetch wrote FETCH_HEAD but the
394// local branch ref was not updated. Decides whether to reset, ask the user, or
395// abort. The force flag bypasses the user prompt; otherwise an interactive
396// prompt confirms (TTY) or a FlagError is returned (non-TTY).
397func (o *options) resolveDivergence(ctx context.Context) error {
398 fetched, diverged, err := o.localDivergesFromFetchHead()
399 if err != nil {
400 return err
401 }
402 if !diverged {
403 return nil
404 }
406 // A local branch that is simply behind, which is what a checked-out branch
407 // looks like after the MR gained commits, has nothing to lose: fast-forward it
408 // instead of asking to reset.
409 if o.localIsAncestorOfFetchHead() {
410 return o.fastForward(fetched)
411 }
413 onTarget, err := o.guardReset(fetched)
414 if err != nil {
415 return err
416 }
418 if !o.force {
419 if !o.io.PromptEnabled() {
420 return cmdutils.FlagError{Err: fmt.Errorf("local branch %q has diverged from remote. Pass --force to reset it (discards local commits on this branch)", o.branch)}
421 }
422 var confirmed bool
423 if err := o.io.Confirm(ctx, &confirmed, o.divergencePrompt()); err != nil {
424 return err
425 }
426 if !confirmed {
427 return cmdutils.CancelError()
428 }
429 }
430 return o.applyReset(onTarget, fetched)
431}
433// divergencePrompt wording depends on the mode. In worktree mode nothing in
434// the current directory changes, only the branch ref moves, so the default
435// wording would describe the very thing --worktree exists to avoid. An existing
436// worktree is named, since that is where the reviewer will see the change.
437func (o *options) divergencePrompt() string {
438 if o.worktreeInPlace {
439 return fmt.Sprintf("Local branch %q has diverged from remote. Reset it in the worktree at %q (discards local commits on this branch, current directory untouched)?", o.branch, o.worktree)
440 }
441 if o.worktree != "" {
442 return fmt.Sprintf("Local branch %q has diverged from remote. Reset the branch before creating the worktree (discards local commits on this branch, current directory untouched)?", o.branch)
443 }
444 return fmt.Sprintf("Local branch %q has diverged from remote. Reset to remote (discards local commits on this branch)?", o.branch)
445}
447// localDivergesFromFetchHead reports whether the local branch ref points at a
448// different commit than FETCH_HEAD. A missing local branch is treated as "no
449// divergence" so downstream code surfaces any error.
450func (o *options) localDivergesFromFetchHead() (string, bool, error) {
451 localSHA := o.localBranchSHA()
452 if localSHA == "" {
453 return "", false, nil
454 }
455 fetchSHA, err := o.gr.Git("rev-parse", "FETCH_HEAD^{commit}")
456 if err != nil {
457 return "", false, err
458 }
459 fetched := strings.TrimSpace(fetchSHA)
460 return fetched, localSHA != fetched, nil
461}
463// localIsAncestorOfFetchHead reports whether FETCH_HEAD descends from the local
464// branch, so the local branch can be fast-forwarded without losing commits.
465func (o *options) localIsAncestorOfFetchHead() bool {
466 _, err := o.gr.Git("merge-base", "--is-ancestor", "refs/heads/"+o.branch, "FETCH_HEAD")
467 return err == nil
468}
470// fastForward moves the local branch to the fetched commit. On the checked-out
471// branch it goes through `git merge --ff-only`, which updates the working tree
472// and refuses if uncommitted changes conflict with the merge.
473//
474// git refuses `branch -f` for a branch a worktree holds, so an in-place update
475// has to run inside that worktree. FETCH_HEAD is per-worktree and that one has
476// its own copy, or none, so the commit is named explicitly.
477func (o *options) fastForward(fetched string) error {
478 var err error
479 if o.worktreeInPlace {
480 err = o.gr.GitWithIO(o.io.StdOut, o.io.StdErr, "-C", o.worktree, "merge", "--ff-only", fetched)
481 if err != nil {
482 return fmt.Errorf("could not fast-forward branch %q in the worktree at %q: %w", o.branch, o.worktree, err)
483 }
484 return nil
485 }
487 currentBranch, symErr := o.gr.Git("symbolic-ref", "--quiet", "--short", "HEAD")
488 if symErr == nil && strings.TrimSpace(currentBranch) == o.branch {
489 err = o.gr.GitWithIO(o.io.StdOut, o.io.StdErr, "merge", "--ff-only", "FETCH_HEAD")
490 } else {
491 err = o.gr.GitWithIO(o.io.StdOut, o.io.StdErr, "branch", "-f", o.branch, "FETCH_HEAD")
492 }
493 if err != nil {
494 return fmt.Errorf("could not fast-forward local branch %q to the merge request: %w", o.branch, err)
495 }
496 return nil
497}
499// guardReset checks whether `git reset --hard FETCH_HEAD` is safe to run for
500// the target branch. Returns whether HEAD is currently the target branch, or an
501// error describing why the reset would destroy uncommitted work.
502func (o *options) guardReset(fetched string) (bool, error) {
503 if o.worktreeInPlace {
504 // The reset lands in the review worktree, so the dirty check belongs there
505 // rather than here. --force must not discard work the reviewer cannot see.
506 unsafe, err := o.unsafeToReset(o.worktree, fetched)
507 if err != nil {
508 return false, err
509 }
510 if unsafe {
511 return false, fmt.Errorf("the worktree at %q has changes that would be lost by reset. Commit, stash, or remove them before resetting branch %q", o.worktree, o.branch)
512 }
513 return false, nil
514 }
515 if o.worktree != "" {
516 // validate() established that the branch is checked out nowhere, so
517 // applyReset moves the ref and the later `worktree add` picks up the head.
518 return false, nil
519 }
521 currentBranch, symErr := o.gr.Git("symbolic-ref", "--quiet", "--short", "HEAD")
522 onTarget := symErr == nil && strings.TrimSpace(currentBranch) == o.branch
523 if !onTarget {
524 return false, nil
525 }
526 unsafe, err := o.unsafeToReset("", fetched)
527 if err != nil {
528 return false, err
529 }
530 if unsafe {
531 return false, fmt.Errorf("working tree has changes that would be lost by reset. Commit, stash, or remove them before resetting branch %q", o.branch)
532 }
533 return true, nil
534}
536// applyReset mutates the local ref to match FETCH_HEAD. Callers must invoke
537// guardReset first and use its returned onTarget value.
538func (o *options) applyReset(onTarget bool, fetched string) error {
539 if o.worktreeInPlace {
540 return o.gr.GitWithIO(o.io.StdOut, o.io.StdErr, "-C", o.worktree, "reset", "--hard", fetched)
541 }
542 if onTarget {
543 return o.gr.GitWithIO(o.io.StdOut, o.io.StdErr, "reset", "--hard", "FETCH_HEAD")
544 }
545 return o.gr.GitWithIO(o.io.StdOut, o.io.StdErr, "branch", "-f", o.branch, "FETCH_HEAD")
546}
548// unsafeToReset reports whether `git reset --hard` to the fetched commit would
549// silently destroy uncommitted work. Two conditions trigger it:
550// 1. Tracked files with modified or staged changes (reset --hard discards them).
551// 2. Untracked files whose paths appear in the fetched tree (reset --hard
552// overwrites them silently — unlike `git checkout`, which refuses).
553//
554// Unrelated untracked files (local notes, build artifacts) are NOT a blocker
555// since reset --hard leaves them alone.
556// dir selects the working tree to inspect: empty for this one, or the review
557// worktree, whose own FETCH_HEAD is unrelated, so the commit is named instead.
558func (o *options) unsafeToReset(dir, fetched string) (bool, error) {
559 run := func(args ...string) (string, error) {
560 if dir != "" {
561 args = append([]string{"-C", dir}, args...)
562 }
563 return o.gr.Git(args...)
564 }
566 tracked, err := run("diff", "--name-only", "HEAD")
567 if err != nil {
568 return false, err
569 }
570 if strings.TrimSpace(tracked) != "" {
571 return true, nil
572 }
573 untracked, err := run("ls-files", "--others", "--exclude-standard")
574 if err != nil {
575 return false, err
576 }
577 if strings.TrimSpace(untracked) == "" {
578 return false, nil
579 }
580 incoming, err := run("ls-tree", "-r", "--name-only", fetched)
581 if err != nil {
582 return false, err
583 }
584 incomingPaths := map[string]struct{}{}
585 for line := range strings.SplitSeq(incoming, "\n") {
586 if line != "" {
587 incomingPaths[line] = struct{}{}
588 }
589 }
590 for line := range strings.SplitSeq(untracked, "\n") {
591 if line == "" {
592 continue
593 }
594 if _, conflict := incomingPaths[line]; conflict {
595 return true, nil
596 }
597 }
598 return false, nil
599}
Diagnostics8 git calls · 65 ms
CallStatusSizeTime065 ms
discover200185 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=185 git.server.agent=git/2.56.g1891de4-Linux git.server.object_format=sha1 git.server.caps=agent ls-refs fetch server-option object-format git.server.fetch=shallow wait-for-done filter git.protocol.version=2 git.pkt.frames=9 git.pkt.data=7 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=185 git.pkt.payload.max=35
ls-refs20058 KiB8 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=59849 git.response.cache=UPDATING git.response.duration_ms=8 git.protocol.version=2 git.pkt.frames=731 git.pkt.data=730 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=59849 git.pkt.payload.max=143 git.ls_refs.count=730 git.ls_refs.head=refs/heads/main
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=4273 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=combine:blob:none+tree:2 git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9 git.fetch.haves.count=0 git.fetch.deepen=1 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=4273 git.pkt.payload.max=4173 git.sideband.band1.bytes=4173 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=11 git.pack.bytes=4173 git.fetch.wide.objects=11 git.fetch.wide.extra_bytes=3930 git.fetch.wide.blobs=0
fetchtree:0 · deepen 1020032 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=32926 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=22 git.pkt.data=20 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=32926 git.pkt.payload.max=32046 git.sideband.band1.bytes=32046 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=80 git.pack.bytes=32046 git.pack.ofs_delta=36 git.pack.ref_delta=0 git.pack.chain.max=2 git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91 git.pack.full=44Open pack map
fetchtree:02001.8 KiB · hit0 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=0 git.response.bytes=1857 git.response.cache=HIT git.response.duration_ms=0 git.fetch.filter=tree:0 git.fetch.wants=dce174ff8c632a19d17eea99c8a9b7c37fb2b592 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1857 git.pkt.payload.max=1830 git.sideband.band1.bytes=1830 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=1830 git.pack.trailer=fb03183b7909876778f740d196d7516811003517Open pack map
fetchtree:0200746 B · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=746 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=f3d413a22af5a9c2fe9aa49709b1cb36d1351a7f git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=746 git.pkt.payload.max=719 git.sideband.band1.bytes=719 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=719 git.pack.trailer=330baf80c59a4208b55120dff7dd824b7952b790Open pack map
fetchtree:0200180 B · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=180 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=798b94905ec5caf72269567e97fe6dba32b63a3c git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=180 git.pkt.payload.max=153 git.sideband.band1.bytes=153 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=153 git.pack.trailer=0357626d2605d28d1849d8be9216332c1b4ca495Open pack map
fetch2006.3 KiB · hit49 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=49 git.response.bytes=6493 git.response.cache=HIT git.response.duration_ms=49 git.fetch.wants=393635ebb773b3038dd649c49ebdea487ba48af1 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=6493 git.pkt.payload.max=6466 git.sideband.band1.bytes=6466 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://gitlab.com/gitlab-org/cli
- Ref
- refs/heads/main
- Commit
- 0dd7574dce9e385c5c30540e6c15657adc6bdce9
- cf-ray
- a5e2fc599e80cf81
- Request
- b96ca352…
- Protocol
- v2 · sha1
- Agent
- git/2.56.g1891de4-Linux
- Filter
- advertised
- Fetch
- shallow wait-for-done filter
- Capabilities
- agent ls-refs fetch server-option object-format