Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check out only a part of a git repository during a bamboo build?

Tags:

git

bamboo

I have a bamboo build that needs to access a small part of a large git repository. In order to save time and disk space, I would like to check out only the part of the repository that is relevant for the build. I already know about shallow checkouts. I want to do more than that and restrict the checkout to just a single folder (and its descendants).

I see this option and I think this is what I have to use, but I haven't been able to get it working: enter image description here

How can I do the minimal checkout that I want?

like image 976
Andrew Eisenberg Avatar asked Nov 05 '22 00:11

Andrew Eisenberg


1 Answers

Easiest is probably to have whoever's hosting the repo tag and commit the particular tree you want. For instance,

On upstream:

git tag quickie $(git commit-tree $(git rev-parse HEAD:path/to/dir) </dev/null)

you:

git fetch upstream quickie

If you want the upstream repo to automatically track a subtree on a branch, you can do (a suitably decrypted version of) something like this:

sed -n 's,^[^ ]* [^ ]* refs/heads/master$,git update-ref refs/heads/master-subtree -m "Auto-tracking master" $(git commit-tree master:subtree -m "Auto-tracking master subtree" $(test -r refs/heads/master-subtree \&\& echo -p refs/heads/master-subtree)),p' | sh -x

which is simpler than it looks. Try this:

mkdir ~/tryitout && cd ~/tryitout && git init foo && git init bar --bare
cat >bar/hooks/post-receive <<'EOF'
sed -n 's,^[^ ]* [^ ]* refs/heads/master$,git update-ref refs/heads/master-subtree -m "Auto-tracking master" $(git commit-tree master:subtree -m "Auto-tracking master subtree" $(test -r refs/heads/master-subtree \&\& echo -p refs/heads/master-subtree)),p' | sh -x
EOF
chmod a+x bar/hooks/post-receive
cd foo
mkdir subtree && touch subtree/oooo && git add . && git commit -am-
git push ../bar master

Late Update --

If you're sharing a filesystem with the other repo, you can do this:

git clone --no-checkout /path/to/local/repo/.git subtree
cd subtree
git commit-tree origin/rev:subtree </dev/null | xargs git checkout -B peek

and you can bounce around at will by changing the rev to suit, origin/master:include, origin/next:include, origin/v1.4:somewhereelsenow, whatever.

I generally have an "empty" branch for large repos. Git does handle one special case of an empty directory:

git mktree </dev/null | xargs git commit-tree | xargs git checkout -b empty
like image 59
jthill Avatar answered Nov 07 '22 21:11

jthill