Fix some minor issues at fetch.git

parent d7a148e3
......@@ -19,6 +19,8 @@
# You should have received a copy of the GNU General Public License
# along with Hdlmake. If not, see <http://www.gnu.org/licenses/>.
"""Module providing the stuff for handling Git repositories"""
import os
from hdlmake.util import path
import logging
......@@ -31,11 +33,15 @@ from .fetcher import Fetcher
class Git(Fetcher):
"""This class provides the Git fetcher instances, that are
used to fetch and handle Git repositories"""
def __init__(self):
pass
@staticmethod
def get_git_toplevel(module):
"""Get the top level for the Git repository"""
cur_dir = module.pool.top_module.path
try:
os.chdir(path.rel2abs(module.path))
......@@ -51,29 +57,24 @@ class Git(Fetcher):
os.chdir(cur_dir)
def fetch(self, module):
"""Get the code from the remote Git repository"""
fetchto = module.fetchto()
if module.source != GIT:
raise ValueError("This backend should get git modules only.")
if not os.path.exists(fetchto):
os.mkdir(fetchto)
cur_dir = module.pool.top_module.path
if module.branch is None:
module.branch = "master"
basename = path.url_basename(module.url)
mod_path = os.path.join(fetchto, basename)
logging.info("Fetching git module: %s" % mod_path)
if basename.endswith(".git"):
basename = basename[:-4] # remove trailing .git
if module.isfetched:
update_only = True
else:
update_only = False
if update_only:
logging.info("Updating module %s" % mod_path)
cmd = "(cd {0} && git checkout {1})"
......@@ -82,13 +83,10 @@ class Git(Fetcher):
logging.info("Cloning module %s" % mod_path)
cmd = "(cd {0} && git clone -b {2} {1})"
cmd = cmd.format(fetchto, module.url, module.branch)
success = True
logging.debug("Running %s" % cmd)
if os.system(cmd) != 0:
success = False
if module.revision is not None and success is True:
logging.debug("cd %s" % mod_path)
os.chdir(mod_path)
......@@ -97,13 +95,13 @@ class Git(Fetcher):
if os.system(cmd) != 0:
success = False
os.chdir(cur_dir)
module.isfetched = True
module.path = mod_path
return success
@staticmethod
def check_commit_id(path):
def check_id(path):
"""Get the commit id for the Git repository at path"""
cur_dir = os.getcwd()
commit = None
stderr = TemporaryFile()
......@@ -122,7 +120,6 @@ class Git(Fetcher):
logging.debug(
"git error message (in %s): %s" %
(path, '\n'.join(errmsg)))
try:
commit = git_out.stdout.readlines()[0].strip()
except IndexError:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment