Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show different color and/or add a symbol to the branch column unless it shows the default #13

Open
4 tasks
strboul opened this issue Sep 12, 2021 · 0 comments
Labels
Effort: high enhancement New feature or request

Comments

@strboul
Copy link
Owner

strboul commented Sep 12, 2021

Show a different color and/or add a symbol to the branch column (like *) unless it shows the default branch name (mostly master, main, release etc.).

Unfortunately, this issue is a bit complex as there's no standard way of getting the default branch name right away.


Programmatically, it's possible to get the branch name in multiple ways:

1. If default branch is set in git config

git config --get init.defaultBranch

2. If the repo was downloaded with git clone

then origin/HEAD is set automatically.

git symbolic-ref refs/remotes/origin/HEAD | cut -d '/' -f4
master
git rev-parse --abbrev-ref origin/HEAD
origin/master

3. Get from the remote

git ls-remote --symref origin HEAD
ref: refs/heads/master  HEAD
28c8d9f868eb9af98618407170da6a63c43e7f62        HEAD

git ls-remote --symref origin HEAD
ref: refs/heads/main    HEAD
597b74a4a04c8741db1000901627745b65e5d69a        HEAD

The problem with this way is: It takes a while to get this from remote, like (~ 2000ms) so it's better
to create a cache file in the home directory (e.g. $HOME/.cache/git-substatus/cache.json)
to make the process faster.

Example cache file:

{
  "cache": [
    {
      "repository": "git-substatus",
      "defaultBranch": "master",
      "cacheTime": "1631264137"
    },
    {
      "repository": "test",
      "default-branch": "main",
      "cacheTime": "1631264137"
    }
  ]
}

The risk of caching is that the repository name isn't failproof as it may be replaced with another repository having the same name. That's why need to find a unique identifier for it?

The caching invalidation can happen every week (168h) and on every time when git-substatus is called with the --fetch option.


TODO:

  • Detect default branch in a repository
  • Display a visual cue if it's checked out to a non default branch
  • Write unit tests (e.g. repos which default branch name isn't master)
  • (Optional) Implement a caching mechanism to retrieve default branch information faster
@strboul strboul added enhancement New feature or request Effort: high labels Sep 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Effort: high enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant