def __init__(self, master_repo=None): """ Setup self.git_repo_manager. If a master_repo is present clone it. Otherwise create a directory in /tmp and init it. @param master_repo: GitRepo representing master. """ if master_repo is None: self.repodir = tempfile.mktemp(suffix='master') self._create_git_repo(self.repodir) self.git_repo_manager = revision_control.GitRepo( self.repodir, self.repodir, abs_work_tree=self.repodir) self._setup_git_environment() # Create an initial commit. We really care about the common case # where there exists a commit in the upstream repo. self._edit('initial_commit_file', 'is_non_empty') self.add() self.commit('initial_commit') else: self.repodir = tempfile.mktemp(suffix='dependent') self.git_repo_manager = revision_control.GitRepo( self.repodir, master_repo.repodir, abs_work_tree=self.repodir) self.git_repo_manager.clone() self._setup_git_environment()
def fetch(self, unused_dest_dir): """ Fetch repo to a temporary location. We use an intermediate temp directory because we have to build an egg for installation. If we can't get at the top commit hash after fetching something is wrong. This can happen when we've cloned/pulled an empty repo. Not something we expect to do. @parma unused_dest_dir: passed in because we inherit from ExternalPackage. @return: True if repo sync was successful. """ self.temp_btsocket_dir = autotemp.tempdir(unique_id='btsocket') try: git_repo = revision_control.GitRepo( self.temp_btsocket_dir.name, self._GIT_URL, None, abs_work_tree=self.temp_btsocket_dir.name) git_repo.reinit_repo_at(self.PROD_BRANCH) if git_repo.get_latest_commit_hash(): return True except: self.temp_btsocket_dir.clean() raise self.temp_btsocket_dir.clean() return False
def fetch(self, unused_dest_dir): """ Fetch repo to a temporary location. We use an intermediate temp directory to stage our installation because we only care about the servo package. If we can't get at the top commit hash after fetching something is wrong. This can happen when we've cloned/pulled an empty repo. Not something we expect to do. @parma unused_dest_dir: passed in because we inherit from ExternalPackage. @return: True if repo sync was successful. """ git_repo = revision_control.GitRepo( self.temp_hdctools_dir, self._GIT_URL, None, abs_work_tree=self.temp_hdctools_dir) git_repo.reinit_repo_at(self.PROD_BRANCH) if git_repo.get_latest_commit_hash(): return True return False
def build_and_install(self, install_dir): """ @param install_dir: destination directory for skylab_inventory installation. """ local_skylab_dir = os.path.join(install_dir, 'infra_skylab_inventory') git_repo = revision_control.GitRepo( local_skylab_dir, self._GIT_URL, abs_work_tree=local_skylab_dir) git_repo.reinit_repo_at(self.MASTER_BRANCH) # The top-level __init__.py for skylab is at venv/skylab_inventory. source = os.path.join(local_skylab_dir, 'venv', 'skylab_inventory') link_name = os.path.join(install_dir, 'skylab_inventory') if (os.path.exists(link_name) and os.path.realpath(link_name) != os.path.realpath(source)): os.remove(link_name) if not os.path.exists(link_name): os.symlink(source, link_name) if git_repo.get_latest_commit_hash(): return True return False
def build_and_install(self, install_dir, master_branch=False): """ Clone if the repo isn't initialized, pull clean bits if it is. Unlike it's hdctools counterpart the chromite repo clones master directly into site-packages. It doesn't use an intermediate temp directory because it doesn't need installation. @param install_dir: destination directory for chromite installation. @param master_branch: if True, install master branch. Otherwise, install prod branch. """ init_branch = (self.MASTER_BRANCH if master_branch else self.PROD_BRANCH) local_chromite_dir = os.path.join(install_dir, 'chromite') git_repo = revision_control.GitRepo( local_chromite_dir, self._GIT_URL, abs_work_tree=local_chromite_dir) git_repo.reinit_repo_at(init_branch) if git_repo.get_latest_commit_hash(): return True return False
def __init__(self, repodir, giturl, weburl=None): self.repodir = repodir self.giturl = giturl self.weburl = weburl self.git_repo = revision_control.GitRepo(self.repodir, self.giturl, self.weburl) # default to same remote path as local self._build = os.path.dirname(self.repodir)
def clone_prod_branch(repo): """Method to clone the prod branch for a given repo under /tmp/ dir. @param repo: Name of the git repo to be cloned. @returns path to the cloned repo. @raises subprocess.CalledProcessError on a command failure. @raised revision_control.GitCloneError when git clone fails. """ repo_dir = '/tmp/%s' % repo print 'Cloning %s prod branch under %s' % (repo, repo_dir) if os.path.exists(repo_dir): infra.local_runner('rm -rf %s' % repo_dir) git_repo = revision_control.GitRepo(repo_dir, GIT_URL[repo]) git_repo.clone(remote_branch=PROD_BRANCH) print 'Successfully cloned %s prod branch' % repo return repo_dir
def build_and_install(self, install_dir): """ Clone if the repo isn't initialized, pull clean bits if it is. Unlike it's hdctools counterpart the dev-util repo clones master directly into site-packages. It doesn't use an intermediate temp directory because it doesn't need installation. @param install_dir: destination directory for chromite installation. """ local_devserver_dir = os.path.join(install_dir, 'devserver') git_repo = revision_control.GitRepo(local_devserver_dir, self._GIT_URL, abs_work_tree=local_devserver_dir) git_repo.reinit_repo_at(self.PROD_BRANCH) if git_repo.get_latest_commit_hash(): return True return False
def build_and_install(self, install_dir): """ Clone if the repo isn't initialized, pull clean bits if it is. @param install_dir: destination directory for suite_scheduler installation. @param master_branch: if True, install master branch. Otherwise, install prod branch. """ local_dir = os.path.join(install_dir, 'suite_scheduler') git_repo = revision_control.GitRepo( local_dir, self._GIT_URL, abs_work_tree=local_dir) git_repo.reinit_repo_at(self.MASTER_BRANCH) if git_repo.get_latest_commit_hash(): return True return False
def git_show_to_temp_file(commit, original_file, new_temp_file): """ 'Git shows' the file in original_file to a tmp file with the name new_temp_file. We need to preserve the filename as it gets reflected in pylints error report. @param commit: commit hash of the commit we're running repo upload on. @param original_file: the path to the original file we'd like to run 'git show' on. @param new_temp_file: new_temp_file is the path to a temp file we write the output of 'git show' into. """ git_repo = revision_control.GitRepo(common.autotest_dir, None, None, common.autotest_dir) with open(new_temp_file, 'w') as f: output = git_repo.gitcmd('show --no-ext-diff %s:%s' % (commit, original_file), ignore_status=False).stdout f.write(output)
def initialize(self): """Initialize inventory repo at the given dir.""" self.git_repo = revision_control.GitRepo( self.inventory_repo_dir, giturl=INTERNAL_INVENTORY_REPO_URL, abs_work_tree=self.inventory_repo_dir) if self.git_repo.is_repo_initialized(): if self.git_repo.status(): raise InventoryRepoDirNotClean( 'The inventory_repo_dir "%s" contains uncommitted ' 'changes. Please clean up the local repo directory or ' 'use another clean directory.' % self.inventory_repo_dir) logging.info('Inventory repo was already initialized, start ' 'pulling.') self.git_repo.checkout('master') self.git_repo.pull() else: logging.info('No inventory repo was found, start cloning.') self.git_repo.clone(shallow=True)