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

Ignore environment variables when executing git command #14

Merged
merged 2 commits into from
Jul 13, 2024

Conversation

FantasyTeddy
Copy link
Contributor

We encountered the issue gohugoio/hugo#8627 seemingly random, until we realized that the environment variable GIT_TRACE was enabled for debugging.
The parsing logic does not handle the additional output very well and therefore panics with the "index out of range" error.

The simplest solution would be to ignore all environment variables.
However, I'm not absolutely sure that this has no unintended side-effects.

@bep
Copy link
Owner

bep commented Jul 12, 2024

However, I'm not absolutely sure that this has no unintended side-effects.

Me, neither.

I suggest that we

  1. Create an options struct to

func Map(repository, revision string) (*GitRepo, error) {

Becomes

func Map(opts Options) (*GitRepo, error) {

And then add a

GetGitCommandFunc func(args ...string) *exec.Command

To the options, with the current implementation as the default.

I can fix the Hugo side of this, but the above would allow us to hook this into Hugo's setup for all of this (there is a fairly strict env var filter already in place).

@FantasyTeddy
Copy link
Contributor Author

Sounds good to me. Do you want me to try to implement your suggestion in this PR? Or will you take over from here and close this PR?

@bep
Copy link
Owner

bep commented Jul 12, 2024

Do you want me to try to implement your suggestion in this PR?

If you could make the changes in this PR, I can tag a release and make the Hugo changes.

@FantasyTeddy
Copy link
Contributor Author

Done, please let me know if I need to change something.

gitmap.go Outdated
GetGitCommandFunc func(args ...string) *exec.Cmd
}

func NewOptions(repository, revision string) Options {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you

  1. Remove NewOptions
  2. Inside Map: Do a if opts.GetGitCommandFunc == nil then opts.GetGitCommandFunc = the default ...

Other than that this looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

gitmap.go Outdated
out, err := exec.Command(gitExec, args...).CombinedOutput()
func git(opts Options, args ...string) ([]byte, error) {
var cmd *exec.Cmd
if opts.GetGitCommandFunc != nil {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we did this in the Map func and set the value on the Options struct; that way we don't have to think about it if we add other git operations (the opt.GetGitCommandFunc is always set).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I did not read your previous comment carefully enough.

@bep bep merged commit 7259440 into bep:master Jul 13, 2024
6 checks passed
@FantasyTeddy FantasyTeddy deleted the ignore-environment-variables branch July 13, 2024 17:49
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.

None yet

2 participants