1
1
import os
2
2
import sys
3
3
import errno
4
+ import logging
4
5
import subprocess
5
6
6
7
import fs
7
8
import fs .path
8
9
import fs .errors
9
10
from gitfs2 import reporter , constants
10
11
12
+ LOG = logging .getLogger (__name__ )
13
+
11
14
12
15
class GitRequire (object ):
13
16
def __init__ (
@@ -49,6 +52,7 @@ def convert_submodule(submodule_string):
49
52
50
53
def git_clone (require , action_required = True ):
51
54
from git import Repo
55
+ from git .exc import GitCommandError
52
56
53
57
if sys .platform != "win32" :
54
58
# Unfortunately for windows user, the following function
@@ -65,24 +69,28 @@ def git_clone(require, action_required=True):
65
69
if action_required :
66
70
try :
67
71
fs .open_fs (local_repo_folder )
68
- reporter .info ("Found repo in %s" % local_repo_folder )
72
+ reporter .info (constants . MESSAGE_FOUND_REPO_FMT % local_repo_folder )
69
73
repo = Repo (local_repo_folder )
70
74
repo .git .pull ()
71
75
if require .reference :
72
76
repo .git .checkout (require .reference )
73
77
elif require .branch :
74
78
repo .git .checkout (require .branch )
75
79
if require .submodule :
76
- reporter .info ("updating submodule" )
80
+ reporter .info (constants . MESSAGE_UPDATE_SUBMODULE )
77
81
repo .git .submodule ("update" )
78
82
except fs .errors .CreateFailed :
79
- reporter .info ("git clone %s" % require .git_url )
83
+ reporter .info (constants . MESSAGE_GIT_CLONE_FMT % require .git_url )
80
84
repo = Repo .clone_from (
81
85
require .git_url , local_repo_folder , ** require .clone_params ()
82
86
)
83
87
if require .submodule :
84
- reporter .info ("checking out submodule" )
88
+ reporter .info (constants . MESSAGE_CHECKOUT_SUBMODULE )
85
89
repo .git .submodule ("update" , "--init" )
90
+ except GitCommandError as e :
91
+ reporter .warn (constants .MESSAGE_GIT_COMMAND_PROBLEM )
92
+ LOG .warn (e )
93
+ return local_repo_folder
86
94
87
95
return local_repo_folder
88
96
@@ -95,7 +103,7 @@ def get_repo_name(repo_url):
95
103
repo = giturlparse .parse (repo_url .rstrip ("/" ))
96
104
return repo .name
97
105
except ParserError :
98
- reporter .error (constants .MESSAGE_INVALID_GIT_URL % repo_url )
106
+ reporter .error (constants .MESSAGE_INVALID_GIT_URL_FMT % repo_url )
99
107
raise
100
108
101
109
0 commit comments