DEV Community

Cover image for Unshallowing a Git repository
Raphaël Pinson for Camptocamp Infrastructure Solutions

Posted on • Edited on

12

Unshallowing a Git repository

GitLab allows to perform shallow repository clones (and it seems to be the default in recent versions from what I can tell).

In order to run r10k, I need a full repository though, because r10k will copy it to cache and use this copy as a reference. This is what happens when you use a shallow repository:

 [2020-05-08 06:53:15 - DEBUG] Replacing /etc/puppetlabs/code/environments/modulesync_update and checking out modulesync_update
 [2020-05-08 06:53:56 - ERROR] Command exited with non-zero exit code:
 Command: git clone /builds/camptocamp/is/puppet/puppetmaster-c2c /etc/puppetlabs/code/environments/modulesync_update --reference /etc/puppetlabs/code/cache/-builds-camptocamp-is-puppet-puppetmaster-c2c
 Stderr:
 Cloning into '/etc/puppetlabs/code/environments/modulesync_update'...
 fatal: reference repository '/etc/puppetlabs/code/cache/-builds-camptocamp-is-puppet-puppetmaster-c2c' is shallow
 Exit code: 128
 [2020-05-08 06:53:56 - DEBUG] Purging unmanaged environments for deployment...
Enter fullscreen mode Exit fullscreen mode

Git provides a fetch --unshallow command which solves the problem, so we just need to run git fetch --unshallow in the repository before running r10k.

However, some of our (older) GitLab installs don't make shallow clones. Instead, they make full clones with a single detached branch, so we need fetch --all instead.

In order to have it work in all configurations, I'm ending up running:

git fetch --unshallow || git fetch --all
Enter fullscreen mode Exit fullscreen mode

And then run r10k on the repository.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (1)

Collapse
 
arturt profile image
Artur Trzop

Thanks. This was helpful.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay