Default behaviour and options
On Travis CI the default behaviour is to use a clone-depth of 50.
TravisCI documentation, git-clone-depth:
git:
depth: 3
# Or remove the --depth flag entirely with:
git:
depth: false
On AppVeyor the default is to clone the whole repository.
AppVeyor offers both setting the clone-depth and an alternative shallow_clone: true
option, where the commit is downloaded as a zip-archive using the GitHub or Bitbucket API. (AppVeyor documentation.)
The description in the reference appveyor.yml:
# fetch repository as zip archive
shallow_clone: true # default is "false"
# set clone depth
clone_depth: 5 # clone entire repository history if not defined
Do not use a depth=1 on your project for CI!
The use of (clone_)depth: 1
often results in a git error when a new commit has been pushed to a branch before the CI platform started cloning the intended commit.
Both on AppVeyor and TravisCI, with normal push operations to a repository on GitHub.
Example output of a failed checkout on AppVeyor:
Build started
git clone -q --depth=1 --branch=<branch_name> https://github.com/<user>/<repo_name>.git C:\projects\<repo_name>
git checkout -qf 53f3f9d4d29985cc6e56764c07928a25d94477ed
fatal: reference is not a tree: 53f3f9d4d29985cc6e56764c07928a25d94477ed
Command exited with code 128
Notice that no specific commit was pulled!
Using AppVeyors alternative shallow_clone: true
:
Build started
Fetching repository commit (6ad0f01)...OK
Total: 781.1 KB in 76 files
I have not seen any issue with projects using the shallow_clone: true
setting.
Restarting builds on old commits
A secondary result when using a limited depth, is that restarting CI builds on old commits will fail when outside this range.
Advice
On AppVeyor I would advice to use shallow_clone: true
if the repository is available on GitHub or Bitbucket.
Unless you want to do git operations on the code this seems the best option.
On TravisCI not setting the depth (and using the default depth of 50) seems reasonable.
You can use a different value if you do not want to trigger historic builds or optimise based on the traffic on the repository.
Cloning dependencies
External dependencies are usually referenced by branch or tag.
When acquiring the tip of a branch or tag is cloned there should not be an issue using the git flag --depth=1
.