2
2
3
3
module OhlohScm
4
4
module Git
5
- class Scm < OhlohScm ::Scm # rubocop:disable Metrics/ClassLength
5
+ class Scm < OhlohScm ::Scm
6
6
def initialize ( core :, url :, branch_name :, username :, password :)
7
7
super
8
8
@branch_name = branch_name || 'master'
@@ -27,7 +27,7 @@ def vcs_path
27
27
28
28
def clone_or_fetch ( remote_scm , callback )
29
29
callback . update ( 0 , 1 )
30
- if status . branch? ( branch_name )
30
+ if status . exist? && status . branch? ( branch_name )
31
31
clean_and_checkout_branch # must be on correct branch, but we want to be careful.
32
32
fetch_new_commits ( remote_scm )
33
33
else
@@ -43,7 +43,7 @@ def fetch_new_commits(remote_scm)
43
43
end
44
44
45
45
def clone_and_create_tracking_branch ( remote_scm )
46
- unless status . scm_dir_exist ?
46
+ unless status . exist ?
47
47
run "rm -rf '#{ url } '"
48
48
run "git clone -q -n '#{ remote_scm . url } ' '#{ url } '"
49
49
end
@@ -54,16 +54,12 @@ def clone_and_create_tracking_branch(remote_scm)
54
54
# We need very high reliability and this sequence gets the job done every time.
55
55
def clean_and_checkout_branch
56
56
return unless status . scm_dir_exist?
57
- return unless status . branch? ( branch_name )
58
57
59
58
run "cd '#{ url } ' && git clean -f -d -x"
60
- clean_git_lock_file
61
- run "cd '#{ url } ' && git reset --hard HEAD"
62
- run "cd '#{ url } ' && git checkout #{ branch_name } --"
63
- end
59
+ return unless status . branch? ( branch_name )
64
60
65
- def clean_git_lock_file
66
- run "rm #{ url } /. git/index.lock" if File . exist? ( " #{ url } /.git/index.lock" )
61
+ run "cd ' #{ url } ' && git checkout #{ branch_name } --"
62
+ run "cd ' #{ url } ' && git reset --hard heads/ #{ branch_name } --"
67
63
end
68
64
69
65
def create_tracking_branch ( branch_name )
0 commit comments