repo create --skipGitInit does not skip local Git setup
Summary
glab repo create --skipGitInit (-s) documents itself as "Skip local repository setup (skips both 'git init' and cloning)." Two code paths do not honor it, and they fail differently depending on whether a project name is passed as a positional argument.
Found while reviewing !3809 (closed), but independent of it.
Bug 1: bare -s in a non-Git directory runs git remote add anyway, and exits 0
Steps to reproduce:
mkdir /tmp/example && cd /tmp/example
glab repo create -sActual result:
✓ Created project on GitLab: Kai Armstrong / example - https://gitlab.com/phikai/example
fatal: not a git repository (or any of the parent directories): .git
Warning: Could not add remote: exit status 128The project is created on GitLab, then addRemote runs unconditionally.
With no positional argument, isPath is true (project_create.go:191), and -s short-circuits the git-init check (project_create.go:137), so needsGitInit stays false. Control then reaches the else at project_create.go:307-313, which calls addRemote with no check that the directory is a Git repository at all.
Because the failure is reported with LogErrorf and the function returns nil (project_create.go:315), the command exits 0 while printing fatal: to the terminal. Scripts that check the exit status see success.
Expected result: with -s, skip the remote entirely, or at minimum do not attempt it outside a Git repository, and do not print fatal:.
Bug 2: -s with a project name still prompts for, and performs, local setup
Steps to reproduce, on a TTY:
glab repo create my-project -sActual result: the command prompts Create a local project directory for <namespace>/my-project? and, if accepted, initializes or clones into ./my-project/.
With len(args) == 1 the command takes the branch at project_create.go:156, so isPath stays false and the isPath block at project_create.go:276 is skipped. Control reaches project_create.go:322, where skipGitInit is never consulted, even though it was read at project_create.go:127. The prompt therefore fires on any TTY, and doSetup drives repoInitializer/repoCloner at project_create.go:330-345, which is the "cloning" that -s says it skips.
Expected result: -s suppresses both the prompt and the local setup, creating only the remote project.
Implementation guide
Both fixes are in internal/commands/project/create/project_create.go:
- Bug 1: guard the
addRemotecall atproject_create.go:308on the directory actually being a Git repository.isGitInitializedis already computed atproject_create.go:133. - Bug 2: include
!skipGitInitin the condition atproject_create.go:323, sodoSetupstaysfalsewhen the flag is passed.
Tests live in internal/commands/project/create/project_create_test.go. The package already stubs addRemote, repoInitializer and repoCloner as package-level variables, so both paths can be asserted without touching the network or the filesystem.
Notes
Both behaviors are "the flag does not do what its help text says", so per the version classification and the second bullet of the compatibility policy these are bug fixes rather than breaking changes.