GitLabgitlab-org
cli
main
1package transfer
3import (
4 "context"
5 "fmt"
7 "github.com/MakeNowJust/heredoc/v2"
8 "github.com/spf13/cobra"
10 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
12 "gitlab.com/gitlab-org/cli/internal/cmdutils"
13 "gitlab.com/gitlab-org/cli/internal/glrepo"
14 "gitlab.com/gitlab-org/cli/internal/iostreams"
15 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
16)
18func NewCmdTransfer(f cmdutils.Factory) *cobra.Command {
19 repoTransferCmd := &cobra.Command{
20 Use: "transfer [repo] [flags]",
21 Short: `Transfer a repository to a new namespace.`,
22 Long: heredoc.Docf(`
23 Moves a project to a different group or user namespace. Specify the
24 destination with %[1]s--target-namespace%[1]s. You must have permission to
25 create projects in the target namespace.
26 `, "`"),
27 Example: heredoc.Doc(`
28 glab repo transfer profclems/glab --target-namespace notprofclems`),
29 Args: cobra.MaximumNArgs(1),
30 Annotations: map[string]string{
31 mcpannotations.Destructive: "true",
32 },
33 RunE: func(cmd *cobra.Command, args []string) error {
34 var err error
36 var client *gitlab.Client
37 var repo glrepo.Interface
38 if len(args) != 0 {
39 // repository is coming from command args, not -R
40 repo, err = glrepo.FromFullName(args[0], f.DefaultHostname(), f.Config())
41 if err != nil {
42 return err
43 }
45 apiClient, err := f.ApiClient(repo.RepoHost())
46 if err != nil {
47 return err
48 }
50 client = apiClient.Lab()
51 } else {
52 client, err = f.GitLabClient()
53 if err != nil {
54 return err
55 }
56 repo, err = f.BaseRepo()
57 if err != nil {
58 return err
59 }
60 }
62 dontPromptForConfirmation, err := cmd.Flags().GetBool("yes")
63 if err != nil {
64 return err
65 }
67 targetNamespace, err := cmd.Flags().GetString("target-namespace")
68 if err != nil {
69 return err
70 }
72 c := f.IO().Color()
73 fmt.Printf(heredoc.Doc(`
74 🔴 WARNING: This operation can be irreversible! 🔴
76 If you don't have access to the target namespace:
78 - You will lose control of the repository.
79 - You won't be able to transfer the repository back to the original namespace, UNLESS you have administrative access
80 to the target namespace.
82 Source repository: %s
83 Target namespace: %s
85 `), c.Yellow(repo.FullName()), c.Yellow(targetNamespace))
87 if !dontPromptForConfirmation {
88 err = confirmTransfer(cmd.Context(), f.IO())
89 if err != nil {
90 return fmt.Errorf("unable to confirm: %w", err)
91 }
92 }
94 opt := &gitlab.TransferProjectOptions{}
95 opt.Namespace = targetNamespace
97 project, _, err := client.Projects.TransferProject(repo.FullName(), opt)
98 if err != nil {
99 return err
100 }
102 f.IO().LogInfof("%s Successfully transferred repository %s to %s.\n",
103 c.GreenCheck(), c.Yellow(repo.FullName()), c.Yellow(project.PathWithNamespace))
105 return nil
106 },
107 }
109 repoTransferCmd.Flags().BoolP("yes", "y", false, "Warning: Skip confirmation prompt and force transfer operation. Transfer cannot be undone.")
110 repoTransferCmd.Flags().StringP("target-namespace", "t", "", "The namespace where your project should be transferred to.")
112 _ = repoTransferCmd.MarkFlagRequired("target-namespace")
114 return repoTransferCmd
115}
117func confirmTransfer(ctx context.Context, ios *iostreams.IOStreams) error {
118 const (
119 performTransferLabel = "Confirm repository transfer"
120 abortTransferLabel = "Abort repository transfer"
121 )
123 options := []string{abortTransferLabel, performTransferLabel}
125 var confirmTransfer string
126 err := ios.Select(ctx, &confirmTransfer, "Continue with the repository transfer?", options)
127 if err != nil {
128 return fmt.Errorf("could not prompt: %w", err)
129 }
131 switch confirmTransfer {
132 case performTransferLabel:
133 return nil
134 case abortTransferLabel:
135 return fmt.Errorf("user aborted operation")
136 default:
137 return fmt.Errorf("invalid value: %s", confirmTransfer)
138 }
139}
Diagnostics8 git calls · 295 ms
CallStatusSizeTime0295 ms
discover200185 B4 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch 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 KiB · hit3 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=HIT git.response.duration_ms=3 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=1 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 · hit1 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=1857 git.response.cache=HIT git.response.duration_ms=1 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:0200614 B · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=4 git.response.bytes=614 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=3a89d0cfc8e81880c982180388e42e561a0b7eee 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=614 git.pkt.payload.max=587 git.sideband.band1.bytes=587 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=587 git.pack.trailer=eb8250f8e8340ff2fafc22c5aba90db34fd906a9Open pack map
fetchtree:0200117 B · hit4 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=281 git.response.bytes=117 git.response.cache=HIT git.response.duration_ms=4 git.fetch.filter=tree:0 git.fetch.wants=c5341215b20619550054bdc8e0fd4ae52d4716cd 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=117 git.pkt.payload.max=90 git.sideband.band1.bytes=90 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=90 git.pack.trailer=13d4878562f434b81321830bbbc1e826e49408d9Open pack map
fetch2001.6 KiB281 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=1588 git.response.cache=MISS git.response.duration_ms=281 git.fetch.wants=400bad3185838add7711b36c6194fce769e50a47 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=1588 git.pkt.payload.max=1561 git.sideband.band1.bytes=1561 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
- a5ea56536cc67089
- Request
- 41cb4795…
- 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