# update local git tree from remote
try:
- if utils.retry(git.update_git_project, (GIT_CACHE_DIR, GERRIT_PROJECT, GIT_URL)):
- if os.path.exists(os.path.join(GIT_CACHE_DIR, GERRIT_PROJECT)):
- print '\nuse local repo as reference to clone'
- if runner.show('git clone %s/%s --reference %s %s' % (GIT_URL, GERRIT_PROJECT, os.path.join(GIT_CACHE_DIR, GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
- print 'use local repo as reference to clone: Failed.'
- shutil.rmtree(os.path.join(GIT_CACHE_DIR, GERRIT_PROJECT))
+ if os.path.exists(os.path.join(GIT_CACHE_DIR, GERRIT_PROJECT)):
+ print '\nuse local repo as reference to clone'
+ if runner.show('git clone %s/%s --reference %s %s' % (GIT_URL, GERRIT_PROJECT, os.path.join(GIT_CACHE_DIR, GERRIT_PROJECT), '%s/%s' % (tmpdir,GERRIT_PROJECT)))[0]:
+ print 'use local repo as reference to clone: Failed.'
+ shutil.rmtree(os.path.join(GIT_CACHE_DIR, GERRIT_PROJECT))
except Exception, ex:
print '\nExcept occur when use reference repo to clone code'
print ex
--- /dev/null
+#!/usr/bin/env python
+# vim: ai ts=4 sts=4 et sw=4
+
+"""This script will pull latest change to local when remote ref updated..
+"""
+
+# internal module
+from common import utils
+from common import git
+from common.envparas import export
+
+envparas = ['GERRIT_PROJECT',
+ 'GERRIT_SSHPORT',
+ 'GERRIT_USERNAME',
+ 'GERRIT_HOSTNAME',
+ 'GIT_CACHE_DIR']
+export(envparas, locals())
+GIT_URL = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
+
+if __name__ == '__main__':
+ print '---[JOB STARTED]----------------------------------------'
+
+ # update local git tree from remote
+ try:
+ if not utils.retry(git.update_git_project, (GIT_CACHE_DIR, GERRIT_PROJECT, GIT_URL)):
+ print '\nUpdate local git failed!'
+ exit(1)
+ except Exception, ex:
+ print '\nExcept occur when updating local git tree'
+ print ex
+ exit(1)