diff options
author | Torben <torben.letorbi@gmail.com> | 2016-07-08 15:11:03 +0200 |
---|---|---|
committer | Torben <torben.letorbi@gmail.com> | 2016-07-08 15:11:03 +0200 |
commit | 2e25cb624a41143bebaea6ec59cce2a2b3b3c3a3 (patch) | |
tree | 1c90c76c9abab6b129bba0b8bfebedb2ce93ec07 | |
parent | 28094bced35e36bc3f16daeb27ba0804ef1c733f (diff) | |
download | Git-Auto-Deploy-2e25cb624a41143bebaea6ec59cce2a2b3b3c3a3.zip Git-Auto-Deploy-2e25cb624a41143bebaea6ec59cce2a2b3b3c3a3.tar.gz Git-Auto-Deploy-2e25cb624a41143bebaea6ec59cce2a2b3b3c3a3.tar.bz2 |
Add logging and unset GIT_DIR to git clone method
-rw-r--r-- | gitautodeploy/gitautodeploy.py | 6 | ||||
-rw-r--r-- | gitautodeploy/wrappers/git.py | 36 |
2 files changed, 33 insertions, 9 deletions
diff --git a/gitautodeploy/gitautodeploy.py b/gitautodeploy/gitautodeploy.py index af737cc..095401a 100644 --- a/gitautodeploy/gitautodeploy.py +++ b/gitautodeploy/gitautodeploy.py @@ -116,11 +116,7 @@ class GitAutoDeploy(object): else: # Clone repository logger.info("Repository %s not present and needs to be cloned" % repo_config['url']) - ret = GitWrapper.clone(url=repo_config['url'], branch=repo_config['branch'], path=repo_config['path']) - if ret == 0 and os.path.isdir(repo_config['path']): - logger.info("Repository %s successfully cloned" % repo_config['url']) - else: - logger.error("Unable to clone %s branch of repository %s" % (repo_config['branch'], repo_config['url'])) + GitWrapper.clone(repo_config) def ssh_key_scan(self): import re diff --git a/gitautodeploy/wrappers/git.py b/gitautodeploy/wrappers/git.py index 3b1bd45..19820ed 100644 --- a/gitautodeploy/wrappers/git.py +++ b/gitautodeploy/wrappers/git.py @@ -32,9 +32,8 @@ class GitWrapper(): commands.append('git checkout -f -B ' + repo_config['branch'] + ' -t ' + repo_config['remote'] + '/' + repo_config['branch']) commands.append('git submodule update --init --recursive') - #commands.append('git update-index --refresh') - # All commands needs to success + # All commands need to success for command in commands: res = ProcessWrapper().call(command, cwd=repo_config['path'], shell=True) @@ -50,9 +49,38 @@ class GitWrapper(): return int(res) @staticmethod - def clone(url, branch, path): + def clone(repo_config): + """Clones the latest version of the repo from the git server""" + import logging from process import ProcessWrapper - res = ProcessWrapper().call(['git clone --recursive ' + url + ' -b ' + branch + ' ' + path], shell=True) + import os + import platform + + logger = logging.getLogger() + logger.info("Cloning repository %s" % repo_config['path']) + + # Only pull if there is actually a local copy of the repository + if 'path' not in repo_config: + logger.info('No local repository path configured, no clone will occure') + return 0 + + commands = [] + commands.append('unset GIT_DIR') + commands.append('git clone --recursive ' + repo_config['url'] + ' -b ' + repo_config['branch'] + ' ' + repo_config['path']) + + # All commands need to success + for command in commands: + res = ProcessWrapper().call(command, shell=True) + + if res != 0: + logger.error("Command '%s' failed with exit code %s" % (command, res)) + break + + if res == 0 and os.path.isdir(repo_config['path']): + logger.info("Repository %s successfully cloned" % repo_config['url']) + else: + logger.error("Unable to clone repository %s" % repo_config['url']) + return int(res) @staticmethod |