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

Set length of abbreviated commit id in git describe #299

Merged
merged 1 commit into from
Sep 16, 2021

Conversation

lbulej
Copy link
Member

@lbulej lbulej commented Sep 16, 2021

This seems to be needed because the command (as used in various scripts) suddenly started returning commit id with one extra
character, resulting in a mismatch between git describe and the git-described version produced by the sbt-git plugin (at least on my machine with git 2.31.1). Due to this, the pre-push readme check fails to find the right JAR and aborts the push.

This seems to be needed because the command (as used in various
scripts) suddenly started returning commit id with one extra
letter, resulting in a mismatch between `git describe` and the
version produced by the `sbt-git` plugin.
@lbulej lbulej merged commit 346a66a into master Sep 16, 2021
@vhotspur
Copy link
Member

Perhaps it would make sense to ensure (enforce) that the same length is always used by sbt-git too (and upgrading the length to 12 to make it last virtually forever).

git.useGitDescribe := false

git.formattedShaVersion := {
  val describedVersion = git.gitDescribedVersion.value.getOrElse("")
  val describedVersionNoHash = describedVersion.substring(0, describedVersion.lastIndexOf("-"))
  val shortCommitSha = git.gitHeadCommit.value.getOrElse("").substring(0, 7)
  val suffix = git.makeUncommittedSignifierSuffix(git.gitUncommittedChanges.value, git.uncommittedSignifier.value)
  git.gitHeadCommit.value map { _ => s"${describedVersionNoHash}-g${shortCommitSha}${suffix}" }
}

@lbulej lbulej deleted the topic/git-const-abbrev branch September 16, 2021 08:38
@lbulej
Copy link
Member Author

lbulej commented Sep 16, 2021

Perhaps it would make sense to ensure (enforce) that the same length is always used by sbt-git too (and upgrading the length to 12 to make it last virtually forever).

It surely would, but looking into sbt-git code did not reveal an abbrev-like setting that I could use easily, without having to experiment with SBT tasks :-) What you propose looks fine and can go right in even though I would like it better as a sbt-git setting.

@vhotspur
Copy link
Member

I would like it better as a sbt-git setting.

Same here. I only found sbt/sbt-git#155 (from 2018) and the code above was a mix of existing sbt-git source code and other fragments from GitHub. It looks ugly but I doubt there is a better way (because describedVersion is never constructed from parts as it comes from the command itself or from JGit).

@lbulej
Copy link
Member Author

lbulej commented Sep 16, 2021

I would like it better as a sbt-git setting.

... (because describedVersion is never constructed from parts as it comes from the command itself or from JGit).

This is why I did not originally understand why the pre-commit hook was failing. I always assumed that sbt-git just gives me the output of git describe, so even if git suddenly started using more characters, sbt-git should just pass it on. It took me a while to discover it, because the difference in one character in the JAR file name was barely discernible and I saw what I expected to see :-) I didn't find anything immediately amiss in sbt-git and did not dig into JGit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants