Skip to content

remove requirement for git repo with a remote pointing at a real repo

Currently glab requires a local git repo and a remote GitLab project for commands that in theory should not need access to these at all. This is sometimes a fairly annoying usability issue.

It would be great if this requirement were relaxed, so that a GitLab project (and local git repo) were only required for situations that operate on a project/repo in some way.

The error messages for defaults that do require a GitLab project could mention that instead of asking for a local git repository, and then asking for a GitLab project and then for one that exists. They could also mention related options that don't require a GitLab repo.

Below is an illustration of this in the situation of listing your personal access tokens from your home directory, but it also applies to other commands too.

Here is how a non-interactive approach could work:

~ $ glab token list
GitLab project not found or supplied
Try these options: --user @me --group group --repo user/repo

~ $ glab token list --user @me
...

Here is how a more interactive approach could work:

~ $ glab token list
GitLab project not found or supplied
? Choose a token source [Use arrows to move, type to filter]
> User
  Group
  Project
  Cancel
...
? Choose a token source User
? Choose a user
> @me
  Other user
  Cancel
...
? Choose a token source Group
? Choose a group
> foo/bar
  Other group
  Cancel
...
? Choose a token source Project
? Choose a project
> pabs3/foo
  pabs3/bar
  Other user
  Other project
  Cancel

Currently there are many more steps required:

~ $ glab token list
fatal: not a git repository (or any of the parent directories): .git
git: exit status 128

~ $ glab token list --help
...

~ $ glab token list --user @me
fatal: not a git repository (or any of the parent directories): .git
git: exit status 128

~ $ mkdir foo ; cd foo

~/foo $ glab token list --user @me
fatal: not a git repository (or any of the parent directories): .git
git: exit status 128

~/foo $ git init
Initialized empty Git repository in /home/pabs/foo/.git/

~/foo (main #) $ glab token list --user @me
no git remotes found

~/foo (main #) $ git remote add foo bar

~/foo (main #) $ glab token list --user @me
none of the git remotes configured for this repository point to a known GitLab host. Please use `glab auth login` to authenticate and configure a new host for glab.

Configured remotes: 

~/foo (main #) $ git remote add bar https://gitlab.com/

~/foo (main #) $ glab token list --user @me
none of the git remotes configured for this repository point to a known GitLab host. Please use `glab auth login` to authenticate and configure a new host for glab.

Configured remotes: 

~/foo (main #) $ git remote add baz https://gitlab.com/foo/bar

~/foo (main #) $ glab token list --user @me
1 error occurred:
        * foo/bar: 404 Not Found



~/foo (main #) $ git remote add glab https://gitlab.com/gitlab-org/cli

~/foo (main #) $ glab token list
GET https://gitlab.com/api/v4/projects/gitlab-org/cli/access_tokens: 401 {message: 401 Unauthorized}

~/foo (main #) $ glab token list --user @me
ID       NAME                  ACCESS_LEVEL ACTIVE  REVOKED  CREATED_AT           EXPIRES_AT LAST_USED_AT         SCOPES                                                                              
...
  
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information