xorpaul / g10k

my r10k fork in Go
Apache License 2.0
125 stars 50 forks source link

-clonegit unexpectedly fails with commit refs #213

Closed anarcat closed 1 year ago

anarcat commented 1 year ago

Hi! First, thanks for the -clonefile parameter from #210, really appreciated. However, using it on my puppetfile fails in an unexpected and ambiguous way:

anarcat@curie:puppet$ LANG=C.UTF-8 g10k -clonegit -puppetfile 
Resolving Forge modules (17/17)    0s [====================================================================] 100%
Resolving Git modules (12/12)    0s [====================================================================] 100%
WARN: git repository https://github.com/xneelo/hetzner-needrestart.git does not exist or is unreachable at this moment! Error: exit status 128 Cloning into 'modules/needrestart'...
warning: Could not find remote branch 54981f1eaee3c7650aeb1f419e7d2f42ed16bfc0 to clone.
fatal: Remote branch 54981f1eaee3c7650aeb1f419e7d2f42ed16bfc0 not found in upstream origin

Failed to resolve git module 'needrestart' with repository https://github.com/xneelo/hetzner-needrestart.git and branch/reference '54981f1eaee3c7650aeb1f419e7d2f42ed16bfc0' used in control repository branch 'cmdlineparam' or Puppet environment 'cmdlineparam'
anarcat@curie:puppet[1]$ 

this seems to say that the repository is "unreachable", but that's not actually the case. The repo is reachable, and that ref does exist:

anarcat@curie:puppet$ git  clone -q https://github.com/xneelo/hetzner-needrestart && git -C hetzner-needrestart/ reset --hard 54981f1eaee3c7650aeb1f419e7d2f42ed16bfc0 && echo success
HEAD is now at 54981f1 do not remove existing README file (#22)
success
anarcat@curie:puppet$ 

the problem is that g10k tries to do this, which git does not support:

anarcat@curie:puppet$ git clone --single-branch --branch 54981f1eaee3c7650aeb1f419e7d2f42ed16bfc0 https://github.com/xneelo/hetzner-needrestart.git
Cloning into 'hetzner-needrestart'...
warning: Could not find remote branch 54981f1eaee3c7650aeb1f419e7d2f42ed16bfc0 to clone.
fatal: Remote branch 54981f1eaee3c7650aeb1f419e7d2f42ed16bfc0 not found in upstream origin
anarcat@curie:puppet[128]$ 

So this is a little bit confusing, and it seems like the error message, at the very least, should be fixed to say that the ref is not found or something.

Ideally, we'd support commits on clone as well, it seems this might be something #161 was working on, but i'm not sure.

The workaround is to use the branch name, naturally.

The reason why I use hashes in the Puppetfile is that I use hashes everywhere to ensure supply chain security. I audit a specific hash (either checksum of the tarball or git commit hash) and add that to the Puppetfile so I will know if something gets changed upstream...

Thanks!

xorpaul commented 1 year ago

Check out https://github.com/xorpaul/g10k/releases/tag/v0.9.7

I'm simply doing a git clone and the cd into the folder and switch to the given reference with git checkout

anarcat commented 1 year ago

excellent, i just pushed that release to debian unstable as well, hopefully it will make it in the next stable release :)