fix(repo): honor --skipGitInit in both create paths
Why
repo create --skipGitInit (-s) documents itself as "Skip local repository setup (skips
both git init and cloning)." Two paths did not honour it, and they fail differently
depending on whether a project name is passed. Both are described in
#8533 (closed), with an implementation guide from
@phikai that this follows.
Bare -s in a non-Git directory runs git remote add anyway, and exits 0.
$ mkdir /tmp/example && cd /tmp/example && glab repo create -s
✓ Created project on GitLab: ... - https://gitlab.com/phikai/example
fatal: not a git repository (or any of the parent directories): .git
Warning: Could not add remote: exit status 128
$ echo $?
0With no positional argument isPath is true, and -s short-circuits the git-init check, so
needsGitInit stays false. Control reaches the else that calls addRemote with no check
that the directory is a repository at all. The failure is reported with LogErrorf and the
function returns nil, so a script checking the exit status sees success.
-s with a project name still prompts for, and performs, local setup.
With len(args) == 1 the command leaves isPath false, so the isPath block is skipped and
control reaches the local-setup branch — where skipGitInit is read but never consulted. On a
TTY it prompts Create a local project directory for <namespace>/<project>? and, if accepted,
drives repoInitializer/repoCloner. That is the cloning the flag says it skips.
What
- the remote is added only when
isGitInitialized, which was already computed a few lines up - the local-setup condition gains
!skipGitInit
The first also covers the interactive case where the user declines git init: that path
reaches the same else, and there is no repository for a remote to go into either way.
Verification
Both tests t.Chdir into an empty temp directory, so git rev-parse --git-dir fails and
isGitInitialized is false — the reported setup rather than an approximation of it.
| check | result |
|---|---|
go test ./internal/commands/project/... |
ok, all packages |
go vet ./internal/commands/project/create/... |
clean |
make gen-docs then git status |
clean, so check_docs_update has nothing to report |
Mutation-tested, and the second one changed the test because of what the mutation showed:
| mutation | result |
|---|---|
revert the isGitInitialized guard |
FAIL — does not touch the remote, in 3s |
revert !skipGitInit |
FAIL — no prompt and no local setup, in 10s |
The second mutation originally hung rather than failing: the reintroduced bug prompts, and the confirm blocked forever on a TTY nobody is typing into. A test whose failure mode is a timed-out CI job is not much of a regression test, so it now runs the command under a context deadline — with the flag honoured it finishes in milliseconds, and if it is ignored the deadline turns the hang into a plain failure with a message saying what happened.
Closes #8533 (closed)