Exemple #1
0
    def update_dist_git(self, version, release):
        with Chdir(self.path):
            # Add new Dockerfile
            subprocess.check_call(["git", "add", "Dockerfile"])

            # Add the scripts directory if it exists
            if os.path.exists(os.path.join(self.path, "scripts")):
                subprocess.check_call(["git", "add", "scripts"])

        commit_msg = "Sync"

        if self.source_repo_name:
            commit_msg += " with %s" % self.source_repo_name

        if self.source_repo_commit:
            commit_msg += ", commit %s" % self.source_repo_commit

        commit_msg += ", release %s-%s" % (version, release)

        with Chdir(self.path):
            # Commit the change
            self.log.info("Commiting with message: '%s'" % commit_msg)
            subprocess.check_output(["git", "commit", "-m", commit_msg])

            untracked = subprocess.check_output(
                ["git", "ls-files", "--others", "--exclude-standard"])

            if untracked:
                self.log.warn(
                    "There are following untracked files: %s. Please review your commit."
                    % ", ".join(untracked.splitlines()))

            diffs = subprocess.check_output(
                ["git", "diff-files", "--name-only"])

            if diffs:
                self.log.warn(
                    "There are uncommited changes in following files: '%s'. Please review your commit."
                    % ", ".join(diffs.splitlines()))

        if self.tools.decision("Do you want to review your changes?"):
            with Chdir(self.path):
                subprocess.call(["bash"])

        if self.tools.decision("Do you want to push the commit?"):
            print("")
            with Chdir(self.path):
                self.log.info("Pushing change to the upstream repository...")
                subprocess.check_output(["git", "push", "-q"])
                self.log.info("Change pushed.")

                if self.tools.decision(
                        "Do you want to execute a build on OSBS?"):
                    subprocess.call(["rhpkg", "container-build"])
Exemple #2
0
 def clean(self):
     """ Removes old generated scripts, repos and cct directories """
     with Chdir(self.output):
         for d in ["scripts", "repos", "cct"]:
             if os.path.exists(d):
                 self.log.info("Removing old '%s' directory" % d)
                 subprocess.check_output(["git", "rm", "-rf", d])
Exemple #3
0
    def clean_scripts(self):
        """ Removes the scripts directory from staging and disk """

        with Chdir(self.path):
            if os.path.exists("scripts"):
                self.log.info("Removing old scripts directory")
                subprocess.check_output(["git", "rm", "-rf", "scripts"])
Exemple #4
0
    def repo_info(path):

        with Chdir(path):
            if subprocess.check_output(["git", "rev-parse", "--is-inside-work-tree"]).strip() != "true":
                raise Exception("Directory %s doesn't seem to be a git repository. Please make sure you specified correct path." % path)

            name = os.path.basename(subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).strip())
            branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip()
            commit = subprocess.check_output(["git", "rev-parse", "HEAD"]).strip()

        return name, branch, commit
Exemple #5
0
 def prepare(self):
     if os.path.exists(self.output):
         with Chdir(self.output):
             self.log.info("Pulling latest changes in repo %s..." % self.repo)
             subprocess.check_output(["git", "fetch"])
             subprocess.check_output(["git", "checkout", "-f", self.branch], stderr=subprocess.STDOUT)
             subprocess.check_output(["git", "reset", "--hard", "origin/%s" % self.branch])
         self.log.debug("Changes pulled")
     else:
         self.log.info("Cloning %s git repository (%s branch)..." % (self.repo, self.branch))
         subprocess.check_output(["rhpkg", "-q", "clone", "-b", self.branch, self.repo, self.output])
         self.log.debug("Repository %s cloned" % self.repo)
Exemple #6
0
    def after_sources(self, files):
        if not self.args.dist_git_enable:
            return

        with Chdir(self.output):
            self.update_lookaside_cache(files)
            self.git.add()

            if self.git.stage_modified():
                self.git.commit()
                self.git.push()
            else:
                self.log.info("No changes made to the code, committing skipped")

            self.build()
Exemple #7
0
    def prepare(self):
        self.log.debug("Resetting git repository...")

        # Reset all changes first - nothing should be done by hand
        with Chdir(self.path):
            subprocess.check_output(["git", "reset", "--hard"])

        # Just check if the target branch is correct
        if not self.tools.decision(
                "You are currently working on the '%s' branch, is this what you want?"
                % self.branch):
            print("")
            self.switch_branch()

        self.old_version, self.old_release = self.read_version_and_release()
Exemple #8
0
    def switch_branch(self):

        with Chdir(self.path):
            branches = subprocess.check_output(
                ["git", "for-each-ref", "--format=%(refname)", "refs/heads"])

        branches = [b.strip().split("/")[-1] for b in branches.splitlines()]

        self.log.info("Available branches:")

        for branch in branches:
            self.log.info(branch)

        target_branch = raw_input("\nTo which branch do you want to switch? ")

        if not target_branch in branches:
            print("")
            self.switch_branch()

        with Chdir(self.path):
            # Checkout the correct branch
            self.log.info("Switching to '%s' branch" % target_branch)
            subprocess.check_output(
                ["git", "checkout", "-q", "-f", target_branch])
Exemple #9
0
 def update_lookaside_cache(self, files):
     with Chdir(self.path):
         self.log.info("Updating lookaside cache...")
         subprocess.check_output(["rhpkg", "new-sources"] + files)
         self.log.info("Update finished.")