Skip to content

Commit 330cf69

Browse files
committed
Cleanup hg repo instead of using bare clone
`hg clone -U` creates bare repository. Bare repositories don't return trunk commits with `hg log -f`.
1 parent 3a57b44 commit 330cf69

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/ohloh_scm/hg/scm.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,27 @@ def clone_or_fetch(remote_scm, callback)
2525

2626
status.exist? ? revert_and_pull(remote_scm) : clone_repository(remote_scm)
2727

28+
clean_up_disk
29+
2830
callback.update(1, 1)
2931
end
3032

3133
def clone_repository(remote_scm)
3234
run "rm -rf '#{url}'"
33-
run "hg clone -U '#{remote_scm.url}' '#{url}'"
35+
run "hg clone '#{remote_scm.url}' '#{url}'"
3436
end
3537

3638
def revert_and_pull(remote_scm)
3739
branch_opts = "-r #{remote_scm.branch_name}" if branch_name
3840
run "cd '#{url}' && hg revert --all && hg pull #{branch_opts} -u -y '#{remote_scm.url}'"
3941
end
42+
43+
def clean_up_disk
44+
return unless FileTest.exist?(url)
45+
46+
run "cd #{url} && find . -maxdepth 1 -not -name .hg -not -name . -print0"\
47+
' | xargs -0 rm -rf --'
48+
end
4049
end
4150
end
4251
end

spec/ohloh_scm/hg/scm_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
require 'spec_helper'
22

33
describe 'Hg::Scm' do
4-
it 'must pull hg repository' do
4+
it 'must pull hg repository and clean up non .hg files' do
55
with_hg_repository('hg') do |src|
66
tmpdir do |dir|
77
dest = OhlohScm::Factory.get_core(scm_type: :hg, url: dir)
88
dest.status.wont_be :exist?
99

1010
dest.scm.pull(src.scm, TestCallback.new)
1111
dest.status.must_be :exist?
12+
Dir.entries(dir).sort.must_equal ['.', '..', '.hg']
1213

1314
# Commit some new code on the original and pull again
1415
run_p "cd '#{src.scm.url}' && touch foo && hg add foo && hg commit -u test -m test"
1516
src.activity.commits.last.message.must_equal "test\n"
1617

1718
dest.scm.pull(src.scm, TestCallback.new)
19+
Dir.entries(dir).sort.must_equal ['.', '..', '.hg']
1820
end
1921
end
2022
end

0 commit comments

Comments
 (0)