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

hcp: don't continue if HEAD doesn't exist #13165

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

lbajolet-hashicorp
Copy link
Contributor

In HCP's metadata package, especially the VCS/git parts, we keep the current HEAD for a repository, along with the state it is in, in order to report it to HCP Packer when the build completes.

However, when a build is run on a template from an empty Git repository, and HCP Packer is enabled, the code would crash when trying to get the information on the current HEAD, as it doesn't exist.

The git library we use returns an error in such a case, but this was ignored, leading to a crash when attempting to get the hash to this reference later on.

This commit fixes the problem by NOT ignoring the error to get the head, and immediately stop processing the git data as it doesn't yet exist.

In HCP's metadata package, especially the VCS/git parts, we keep the
current HEAD for a repository, along with the state it is in, in order
to report it to HCP Packer when the build completes.

However, when a build is run on a template from an empty Git repository,
and HCP Packer is enabled, the code would crash when trying to get the
information on the current HEAD, as it doesn't exist.

The git library we use returns an error in such a case, but this was
ignored, leading to a crash when attempting to get the hash to this
reference later on.

This commit fixes the problem by NOT ignoring the error to get the head,
and immediately stop processing the git data as it doesn't yet exist.
@lbajolet-hashicorp lbajolet-hashicorp merged commit 69ec781 into main Sep 13, 2024
12 checks passed
@lbajolet-hashicorp lbajolet-hashicorp added the backport/1.11.x Backport PR changes to `release/1.11.x` label Sep 13, 2024
@lbajolet-hashicorp lbajolet-hashicorp deleted the fix_panic_on_empty_git_repo_hcp branch September 13, 2024 14:52
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/1.11.x Backport PR changes to `release/1.11.x` bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants