# README
git-prep-directory
Build tools friendly way of repeatedly cloning a git repository using a submodule cache and keeping timestamps to commit times.
Concept
Executing the tool/library repeatedly on the same repository with different commit refs results in two optimizations:
- Faster clone times due to less network traffic as most submodules change so infrequently that they are likely already exist in the submodule cache.
- Faster build times for tools like Make and Docker as unchanged files keep their timestamp this are cached by the build tools.
For each execution of a given commit ref the tool/library does the follow steps:
- Clone the given repository
- Checkout the given revision
- Find all submodules and check if they are already cached
- If cached, assert the required commit is checked out and initialize them
- If not cached, checkout the submodule and store it in the cache.
- Set the timestamp of all files and directories to their respective commit time.
This results in the following path hierarchy:
.
└── src
├── HEAD
├── c <-- repository commits
│ ├── 39529a7ed3
│ ├── 5e90e55e6b
│ ├── 607f0489ec
│ └── :
├── config
├── index
├── modules <-- submodules cache
│ ├── path/to/submodule/1
│ ├── path/to/submodule/2
│ ├── path/to/submodule/3
│ └── :
├── objects
├── packed-refs
└── refs
Command line tool
Installation
$ go get github.com/sensiblecodeio/git-prep-directory/cmd/git-prep-directory
Usage
$ git-prep-directory --help
NAME:
git-prep-directory - Build tools friendly way of repeatedly cloning a git
repository using a submodule cache and setting file timestamps to commit times.
USAGE:
git-prep-directory [global options] command [command options] [arguments...]
VERSION:
1.0.0
COMMANDS:
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--url, -u URL to clone
--ref, -r ref to checkout
--destination, -d "./src" destination dir
--help, -h show help
--version, -v print the version
Go Library
import "github.com/sensiblecodeio/git-prep-directory"
buildDirectory, err := git.PrepBuildDirectory(<OUT_PATH>, <REPO_URL>, <GIT_REF>)
# Packages
No description provided by the author
# Functions
AlreadyHaveRef returns true if ref is sha-like and is in the object database.
Checkout switches branches or restores working tree files.
Chtimes changes the modification and access time of a given file.
Clone clones a git repository as mirror.
Command invokes a `command` in `workdir` with `args`, connecting Stdout and Stderr to Stderr.
CommitTimes returns the most recent committed timestamp of each file in the whole of history.
ContextRun runs cmd within a net Context.
Describe describes a commit given a reference using the most recent tag reachable from it.
Fetch fetches all branches from a given remote.
GetSubmoduleRev returns the revisions of all files in a given submodule.
GetSubmoduleRevs returns the revisions of all files in a given list of submodules.
HaveFile checks if a git directory has files checked out.
LocalMirror creates or updates a mirror of `url` at `gitDir` using `git clone --mirror`.
MultipleErrors reads errors out of a channel, counting only the non-nil ones.
ParseSubmodules returns all submodule definitions given a .gitmodules configuration.
PrepBuildDirectory clones a given repository and checks out the given revision, setting the timestamp of all files to their commit time and putting all submodules into a submodule cache.
PrepSubmodules in parallel initializes all submodules and additionally stores them in a local cache.
RecursiveCheckout recursively checks out repositories; similar to "git clone --recursive".
RevParse parses and formats the git rev of a given git reference.
SafeCleanup recursively removes all files from a given path, which has to be a subfolder of the current working directory.
SetMTimes changes the modification and access time of all files in a given directory to their latest commit time.
# Variables
ShaLike specifies a valid git hash.
# Structs
BuildDirectory holds the git rev and path to a cloned git repository.
ErrMultiple holds a list of errors.
Submodule holds the path, url, and revision to a submodule.