Fix some minor issues at fetch.git

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