def prepFakerootFromGit(fakeroot, installDirectory, repoDirectory, gitURL, sha=None): """Clone a git repository and make a fakeroot out of it. :param fakeroot: path to the directory to use as the root of the RPM's install tree :param installDirectory: Where to put the new git clone :param repoDirectory: what to name the cloned directory :param gitURL: git URL used to clone :param sha (optional): SHA to checkout once we've cloned the repository """ g_logger.debug("Prepping fakeroot in %s", fakeroot) installPath = commonFakerootPrep(fakeroot, installDirectory) with changeToWorkingDir(installPath): g_logger.info("Cloning %s into %s/%s/%s", gitURL, fakeroot, installDirectory, repoDirectory) git.clone(gitURL, directory=repoDirectory) workDirectory = "%s/%s/%s" % (fakeroot, installDirectory, repoDirectory) if sha: with changeToWorkingDir(workDirectory): g_logger.info("Checking out SHA %s in %s", sha, workDirectory) git.checkout(sha) git.resetHard() else: g_logger.info("No sha specified, using head of master") gitVersionData = loadGitDescribeFromDirectory(workDirectory) sourceFiles = os.listdir("%s/%s/%s" % (fakeroot, installDirectory, repoDirectory)) for directoryEntry in sourceFiles: cleanseFakeroot(fakeroot, installDirectory, "%s/%s" % (repoDirectory, directoryEntry)) cleanseFakeroot(fakeroot, installDirectory, repoDirectory) return gitVersionData
def gitCloneIntoFakeroot(fakeroot, installDirectory, repoDirectory, gitURL, sha=None, logger=None): """ Clone a git repository into a specific path in a fakeroot @param fakeroot: path to the directory to use as the root of the RPM's install tree @param installDirectory: Where to put the new git clone @param repoDirectory: what to name the cloned directory @param gitURL: git URL used to clone @param sha (optional): SHA to checkout once we've cloned the repository @param logger - Optional logger object, will be used to output more debugging information. @returns the SHA of the resulting git clone. We may not have been invoked with a specific SHA (we normally build tip of master, for example), but we always want to include the exact SHA packaged in our RPM descriptions. """ if logger: logger.debug("Prepping fakeroot in %s", fakeroot) installPath = "%s/%s" % (fakeroot, installDirectory) with changeToWorkingDir(installPath): if logger: logger.debug("Cloning %s into %s/%s/%s", gitURL, fakeroot, installDirectory, repoDirectory) git.clone(gitURL, directory=repoDirectory) workDirectory = "%s/%s/%s" % (fakeroot, installDirectory, repoDirectory) with changeToWorkingDir(workDirectory): if sha: git.resetHard() logger.debug("Checking out SHA %s in %s", sha, workDirectory) git.checkout(sha) else: logger.debug("No SHA specified, using head of master") return git.getCurrentSha()
def prepFakerootFromGit(fakeroot, installDirectory, repoDirectory, gitURL, sha=None): """Clone a git repository and make a fakeroot out of it. :param fakeroot: path to the directory to use as the root of the RPM's install tree :param installDirectory: Where to put the new git clone :param repoDirectory: what to name the cloned directory :param gitURL: git URL used to clone :param sha (optional): SHA to checkout once we've cloned the repository """ g_logger.debug("Prepping fakeroot in %s", fakeroot) installPath = commonFakerootPrep(fakeroot, installDirectory) with changeToWorkingDir(installPath): g_logger.info("Cloning %s into %s/%s/%s", gitURL, fakeroot, installDirectory, repoDirectory) git.clone(gitURL=gitURL, logger=g_logger, directory=repoDirectory) workDirectory = "%s/%s/%s" % (fakeroot, installDirectory, repoDirectory) if sha: with changeToWorkingDir(workDirectory): g_logger.info("Checking out SHA %s in %s", sha, workDirectory) git.checkout(pathspec=sha, logger=g_logger) git.resetHard(sha=sha, logger=g_logger) else: g_logger.info("No sha specified, using head of master") gitVersionData = loadGitDescribeFromDirectory(workDirectory) sourceFiles = os.listdir("%s/%s/%s" % (fakeroot, installDirectory, repoDirectory)) for directoryEntry in sourceFiles: cleanseFakeroot(fakeroot, installDirectory, "%s/%s" % (repoDirectory, directoryEntry)) cleanseFakeroot(fakeroot, installDirectory, repoDirectory) return gitVersionData