Skip to content

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

@FantasyTeddy FantasyTeddy force-pushed the ignore-environment-variables branch from d570892 to 3328c12 Compare July 12, 2024 14:48
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.

@FantasyTeddy FantasyTeddy force-pushed the ignore-environment-variables branch from 3328c12 to 04dc645 Compare July 12, 2024 16:47
@bep bep merged commit 7259440 into bep:master Jul 13, 2024
@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.

2 participants