fix(df): say git is required when the project can't be found

Description

glab dependency-firewall finds the GitLab project from the Git remote, so it needs git. A Beta customer's CI/CD job image had no git, and the error didn't say that git was the problem:

not a git repository: git: exec: "git": executable file not found in $PATH.

This MR:

  • Adds a hint to the project lookup error in the package manager commands (dfcmd.go) and the package command, only when git isn't on the PATH:

    not a git repository: git: exec: "git": executable file not found in $PATH. git is required, so check that it's installed.

    The check uses LookPath("git"), like attestation verify and cluster agent bootstrap do for the binaries they need. Other lookup errors, such as a directory with no Git remote, are unchanged.

  • States in the help and docs that the command requires git in the CI/CD job image.

The alternative, reading the project from CI_PROJECT_PATH, was discussed in the issue and dropped: no other glab command picks its project from CI/CD variables.

Resolves https://gitlab.com/gitlab-org/cli/-/work_items/8741

How has this been tested?

  • TestBaseRepoErrorSaysGitIsRequired and TestPackageBaseRepoErrorExitsOne check that the hint appears when git is missing.
  • TestBaseRepoErrorWithGitInstalledHasNoGitHint and TestPackageBaseRepoErrorWithGitInstalledHasNoGitHint check that it doesn't appear when git is installed.
  • Ran a built binary: with no git on PATH, the command exits with the hint. With git installed but outside a repository, it shows the original error without the hint.
Edited by Aanjaney Kumar Verma

Merge request reports

Loading
Loading