Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shallow git fetch with the same depth as the git clone #747

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/travis/build/git/clone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def clone_or_fetch
end

def fetch_ref
sh.cmd "git fetch origin +#{data.ref}:", assert: true, retry: true
sh.cmd "git fetch #{fetch_args} origin +#{data.ref}:", assert: true, retry: true
end

def fetch_ref?
Expand All @@ -44,6 +44,10 @@ def clone_args
args
end

def fetch_args
"--depth=#{depth}"
end

def depth
config[:git][:depth].to_s.shellescape
end
Expand Down
13 changes: 12 additions & 1 deletion spec/build/git/clone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
end

let(:cd) { [:cd, 'travis-ci/travis-ci', echo: true] }
let(:fetch_ref) { [:cmd, %r(git fetch origin \+[\w/]+:), assert: true, echo: true, retry: true, timing: true] }
let(:fetch_args) { "--depth=#{depth}" }
let(:fetch_ref) { [:cmd, %r(git fetch #{fetch_args} origin \+[\w/]+:), assert: true, echo: true, retry: true, timing: true] }
let(:checkout_push) { [:cmd, 'git checkout -qf 313f61b', assert: true, echo: true] }
let(:checkout_pull) { [:cmd, 'git checkout -qf FETCH_HEAD', assert: true, echo: true] }

Expand All @@ -65,6 +66,16 @@
describe 'with a ref given' do
before { payload[:job][:ref] = 'refs/pull/118/merge' }
it { should include_sexp fetch_ref }

describe 'with no depth specified' do
it { should include_sexp fetch_ref }
end

describe 'with a custom depth' do
let(:depth) { 1 }
before { payload[:config][:git]['depth'] = depth }
it { should include_sexp fetch_ref }
end
end

describe 'with no ref given' do
Expand Down