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

Add an option to change the abbreviated commit SHA length #608

Closed
Luxray5474 opened this Issue Jan 4, 2019 · 7 comments

Comments

Projects
None yet
2 participants
@Luxray5474
Copy link
Contributor

Luxray5474 commented Jan 4, 2019

Literally every other git interface uses 8 characters in the commit ID abbreviation. Gitlab, GitHub, BitB, Gogs, GitExt, GitKraken, you name it, they all use 8 character long commit ID abbreviations...

why does GitLens only have 7 characters? Some hippie bs? jk

It may not be too much of a bother to some people, but to me it certainly is, especially when I am trying to copy abbreviated commit IDs into a spreadsheet constantly, having most of them initially from other clients, and especially because I cannot change the length, even if I do it in git globally. It just really gets on my nerves!

Please add a feature to at least change the length of the abbreviated commit ID. :)

@eamodio

This comment has been minimized.

Copy link
Owner

eamodio commented Jan 4, 2019

See: #496

The default abbrev length of git is currently 7. Also when I look on GitHub I see 7, the same with GitHub Desktop, and in GitKraken I see 6.

Although I would be open for a PR that adds a setting to make it configurable.

@Luxray5474

This comment has been minimized.

Copy link
Contributor

Luxray5474 commented Jan 5, 2019

I am working on it right now. So far, I have found the location of the value that needs to be changed[1] and have added an option in package.json[2]. However, how do I link that option to the value?

[1] git.ts::271-291

[2] in package.json

"gitlens.advanced.abbreviatedCommitShaLength": {
                    "type": "number",
                    "default": 7,
                    "markdownDescription": "Specifies the length of the abbreviated commit SHA, a.k.a. commit ID. Git default is 7.",
                    "scope": "resource"
                },

Btw, I have never made or worked on a VScode extension before, but I have some JS and OOP experience from working with other software. So I might be really off with the way I'm doing this.

@Luxray5474 Luxray5474 changed the title Please, 8 character long commit ID Is it possible to have an option to change the abbreviated commit SHA length? Jan 5, 2019

@eamodio

This comment has been minimized.

Copy link
Owner

eamodio commented Jan 5, 2019

@Luxray5474 No worries at all, I'm happy to help you through it -- and really appreciate you tackling this!

So you are on the right path for sure.

And you are correct with adding that setting to the package.json -- though lets call it gitlens.advanced.abbreviatedShaLength, and set its scope to window (since this setting will be for the whole "window")

Then in

export interface AdvancedConfig {

Add the abbreviatedShaLength property

And finally reference that new setting in (where you mentioned):

static shortenSha(
ref: string,
strings: { stagedUncommitted?: string; uncommitted?: string; working?: string } = {}
) {
strings = { stagedUncommitted: 'Index', uncommitted: 'Working Tree', working: '', ...strings };
if (ref == null || ref.length === 0) return strings.working;
if (Git.isUncommitted(ref)) {
if (Git.isStagedUncommitted(ref)) return strings.stagedUncommitted;
return strings.uncommitted;
}
const index = ref.indexOf('^');
if (index > 5) {
// Only grab a max of 5 chars for the suffix
const suffix = ref.substring(index).substring(0, 5);
return `${ref.substring(0, 7 - suffix.length)}${suffix}`;
}
return ref.substring(0, 7);
}

via Container.config.advanced.abbreviatedShaLength

Let me know if you have any other questions!

@eamodio

This comment has been minimized.

Copy link
Owner

eamodio commented Jan 5, 2019

Also make sure to make these changes off of the develop branch, not master

@Luxray5474

This comment has been minimized.

Copy link
Contributor

Luxray5474 commented Jan 6, 2019

Ah, nice! Thanks for the guide! I'll let you know if I have anymore questions. Again, I appreciate it :D

@Luxray5474

This comment has been minimized.

Copy link
Contributor

Luxray5474 commented Jan 6, 2019

Yay!!!


Thanks for everything :D I will submit a pull request very soon. Again, thank you so much!

@Luxray5474

This comment has been minimized.

Copy link
Contributor

Luxray5474 commented Jan 6, 2019

Are linebreak and no-floating-promises warnings that prevent me from completing the PR checklist? @eamodio

@eamodio eamodio added the feature label Jan 8, 2019

@eamodio eamodio added this to the Soon™ milestone Jan 8, 2019

@eamodio eamodio changed the title Is it possible to have an option to change the abbreviated commit SHA length? Add an option to change the abbreviated commit SHA length Jan 8, 2019

@eamodio eamodio closed this Jan 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment