Skip to content

HOWTO dev git_lfs

steveoro edited this page Jan 15, 2021 · 1 revision

HOW-TO: Git LFS

References:

Goggles uses the Git LFS utility to store large files directly on the repo.

This is currently done only for the anonymized test DB dump, and for goggles_db only, stored under spec/dummy/db/dump/test.sql.bz2.

You may use the same folder to store your own local DB dumps: these will be ignored by git as long as they are not the above file.

Git LFS allows to store on a separate, dedicated GitHub space the large files, using symlinks inside the Git history to avoid bloating the log size.

Large files marked with git-lfs are then uploaded separately from the rest of the repo upon each git push and managed transparently from the git user point of view.

Installing

From binary

The binary packages include a script which will:

  • Install Git LFS binaries onto the system $PATH

  • Run git-lfs install to perform required global configuration changes:

    $ ./install.sh

From source

  • Place the git-lfs binary on your system’s executable $PATH or equivalent.

  • Git LFS requires global configuration changes once per-machine. This can be done by running:

    $ git lfs install

Notes on Git-LFS files managed inside gems or engines

Git-LFS needs some tweaks when used inside nested dependencies like the goggles_db source repo, because the bundle update or install doesn't necessarily triggers (as of this writing) the download of the separate marked file, given that the bundle call doesn't involve a complete pull or clone from the repository itself.

GogglesDb will work just fine locally. Any other "sibling" project using goggles_db doesn't really need another nested copy of the same dump duplicated inside its own git history log, so you can safely skip the download of this single file. (Besides, you can still access the original dump file if you decide to clone GogglesDb locally.)

Three possible solutions:

1. Skip LFS download for all sibling projects

"Skip download where not needed"

The easiest way to skip this, currently, is by setting GIT_LFS_SKIP_SMUDGE=1 before any command involving the bundling of GogglesDb only from inside a "sibling" project.

For instance (when inside goggles, goggles_api or goggles_admin):

$> GIT_LFS_SKIP_SMUDGE=1 bundle install

or

$> GIT_LFS_SKIP_SMUDGE=1 bundle update goggles_db

2. Flag individual files for fetch exclusion

"Skip download always, then force-download where needed"

You can tell Git LFS to exclude the fetch of specific files, but no one cloning the repository will then be able to fetch those:

# Run this in the root of your shared repository (in the example, 'goggles_db').
# Then commit `.lfsconfig` and push.
$> git config --file=.lfsconfig lfs.fetchexclude "spec/dummy/db/dump/*"

Afterwards, you won't be able to download any LFS objects from spec/dummy/db/dump/*:

$> git clone [email protected]:steveoro/goggles_db.git
$> cd goggles_db

You can force-pull the remote LFS objects in two ways:

2.1. Empty string exclude overrides the setting .lfsconfig bash $> git lfs pull --exclude=""

2.2. Set lfs.fetchexclude in your computer's git config, also overriding .lfsconfig bash $> git config lfs.fetchexclude "" $> git lfs pull

3. Change the LFS server for retrieval

"Offer a packaged download changing the LFS server"

Assuming you're doing this for the shared engine goggles_db, you could add a .lfsconfig file to the root of the repository, setting the lfs.url config key used for file retrieval.

This forces Git LFS to use this URL as the LFS server and not some local path like /home/steve/.rvm/gems/[email protected]/cache/bundler/git/goggles_db-130d6e8e290064278ba9d9ed434853f518126922.git. (which would be the typical result of a bundle update.)

The downside is that this locks you into what is specified inside the github repository (one server for all), though you can override in local clones with git config lfs.url:

# Run this in the root of your shared repository (in the example, 'goggles_db').
# Then commit `.lfsconfig` and push.
$ git config --file=.lfsconfig lfs.url "[email protected]:steveoro/goggles_db.git"
Clone this wiki locally