diff options
author | Torben <torben.letorbi@gmail.com> | 2016-07-08 18:23:26 +0200 |
---|---|---|
committer | Torben <torben.letorbi@gmail.com> | 2016-07-08 18:23:26 +0200 |
commit | 0526f410b5dad1f97efc7c651e3afa55c831fb03 (patch) | |
tree | 6d27dddd82d85652e18ed689e452495d11173395 /gitautodeploy/wrappers/git.py | |
parent | 7720ec0cf45bb0b44e3e5b56116545237918d448 (diff) | |
download | Git-Auto-Deploy-0526f410b5dad1f97efc7c651e3afa55c831fb03.zip Git-Auto-Deploy-0526f410b5dad1f97efc7c651e3afa55c831fb03.tar.gz Git-Auto-Deploy-0526f410b5dad1f97efc7c651e3afa55c831fb03.tar.bz2 |
Initialize repo on start; Use 'reset --hard' for update again
Diffstat (limited to 'gitautodeploy/wrappers/git.py')
-rw-r--r-- | gitautodeploy/wrappers/git.py | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/gitautodeploy/wrappers/git.py b/gitautodeploy/wrappers/git.py index 4ccd863..9bca474 100644 --- a/gitautodeploy/wrappers/git.py +++ b/gitautodeploy/wrappers/git.py @@ -6,6 +6,46 @@ class GitWrapper(): pass @staticmethod + def init(repo_config): + """Init remote url of the repo from the git server""" + import logging + from process import ProcessWrapper + import os + import platform + + logger = logging.getLogger() + logger.info("Initializing repository %s" % repo_config['path']) + + commands = [] + + # On Windows, bash command needs to be run using bash.exe. This assumes bash.exe + # (typically installed under C:\Program Files\Git\bin) is in the system PATH. + if platform.system().lower() == "windows": + commands.append('bash -c "cd \\"' + repo_config['path'] + '\\" && unset GIT_DIR"') + else: + commands.append('unset GIT_DIR') + + commands.append('git remote set-url ' + repo_config['remote'] + " " + repo_config['url']) + commands.append('git fetch ' + repo_config['remote']) + commands.append('git checkout -f -B ' + repo_config['branch'] + ' -t ' + repo_config['remote'] + '/' + repo_config['branch']) + commands.append('git submodule update --init --recursive') + + # All commands need to success + for command in commands: + res = ProcessWrapper().call(command, cwd=repo_config['path'], 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 initialized" % repo_config['path']) + else: + logger.error("Unable to init repository %s" % repo_config['path']) + + return int(res) + + @staticmethod def pull(repo_config): """Pulls the latest version of the repo from the git server""" import logging @@ -25,7 +65,8 @@ class GitWrapper(): else: commands.append('unset GIT_DIR') - commands.append('git checkout -f -B ' + repo_config['branch'] + ' -t ' + repo_config['remote'] + '/' + repo_config['branch']) + commands.append('git fetch ' + repo_config['remote']) + commands.append('git reset --hard ' + repo_config['remote'] + "/" + repo_config['branch']) commands.append('git submodule update --init --recursive') # All commands need to success |