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

TonelLoaderGitVersionStrategy>>#attemptVersionFromGit silently fails when HEAD does not point a branch #137

Closed
eMaringolo opened this issue Nov 19, 2024 · 0 comments
Assignees
Labels
bug Something isn't working importing Issues related with importing from Tonel format
Milestone

Comments

@eMaringolo
Copy link
Collaborator

TonelLoaderGitVersionStrategy>>#attemptVersionFromGit silently fails when .git/HEAD does not point a branch but a commit. In Jenkins this might happen depending on how the checkout is done. In the attached version an error is raised when versioning fails for that reason.

!TonelLoaderGitVersionStrategy privateMethods !

attemptVersionFromGit
	"Private - Attempts to read git metadata from the repository path of the loader (if available)."

	self loader reader repositoryPath
		ifNil: [TonelLoaderError signal: ('There is no repository path specified')]
		ifNotNil: [:repoPath | | gitBranchCommitFile gitBranchPath gitHeadPath commitHash commitDate |
			gitHeadPath := (repoPath append: '.git') append: 'HEAD'.
			gitHeadPath exists
				ifTrue: [| refsPathString headFile stat |
					[
						headFile := CfsReadFileStream open: gitHeadPath asString.
						refsPathString := headFile nextLine.
						refsPathString := refsPathString copyFrom: 6 to: refsPathString size]
							ensure: [headFile close].
					gitBranchPath := (repoPath append: '.git') append: refsPathString.
					gitBranchPath exists
						ifTrue: [
							gitBranchCommitFile := CfsReadFileStream open: gitBranchPath asString.

							[
								commitHash := gitBranchCommitFile nextLine first: 7.
								stat := gitBranchPath cfsStat.
								commitDate :=
									DateAndTime date: stat stMtime first time: stat stMtime last]
										ensure: [gitBranchCommitFile close].
							commitHash isEmptyOrNil
								ifTrue: [
									TonelLoaderError signal:
										('Could not retrieve commit hash from the repository')]
								ifFalse: [
									^(self versionNamePattern
										expandMacrosWith: commitHash
										with: gitBranchPath parts last
										with: commitDate)]]
						ifFalse: [
							TonelLoaderError signal: (
								'There is no git branch path at <1p>' expandMacrosWith: gitBranchPath)]]
				ifFalse: [
					TonelLoaderError signal: (
						'There is no git repository at <1p>'
							expandMacrosWith: self loader reader repositoryPath)]

			].
	^nil! !

ps: Issue reported by Adriaan van Os

@eMaringolo eMaringolo added bug Something isn't working importing Issues related with importing from Tonel format labels Nov 19, 2024
@eMaringolo eMaringolo self-assigned this Nov 27, 2024
eMaringolo added a commit that referenced this issue Nov 27, 2024
@eMaringolo eMaringolo added this to the VAST 14.0.0 milestone Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working importing Issues related with importing from Tonel format
Projects
None yet
Development

No branches or pull requests

1 participant