Skip to content

Stop using short commit hashes #123

@josecelano

Description

@josecelano

We found a bug on a test project that was using git-queue.

When you create a commit git returns the short commit message (d3c882c):

$ git ci -m "add a.txt"
[main (root-commit) d3c882c] add a.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a.txt

We are using SimpleGit as a Git wrapper and it also returns the short commit hash probably because only returns what git commit command returns.

The bug was caused because git-queue assumes a fix short commit hash (7 chars).

As I discussed with @da2ce7 we should not rely on short hashes. Short hashes should be only used for the user interface because they are easier to handle by humans.

It seems neither the SimpleGit nor the git commit command itself has an option to return the full commit hash.

This is the object SimpleGit returns after committing:

{
  author: {
    email: 'bot@nautilus-cyberneering.de',
    name: 'NautilusCyberneering[bot]'
  },
  branch: 'issue-22-job-commit-not-created',
  commit: 'df462c39',
  root: false,
  summary: { changes: 0, insertions: 0, deletions: 0 }
}

As you can see in that case the commit hash contains 8 chars. I asked them if there is an option to get the full hash. But we are pretty sure there is not because it seems git commit command does not have it either.

It seems the only way to get the full hash is with some "plumbing" git commands. I've already described here how to use git commit-tree to create the commit.

I guess we can use something similar in our SimplyGit wrapper.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions