Exemplo n.º 1
0
    def run(self):

        # Determine the app.
        app = self.options["<app>"]

        # Ensure it's a built app
        logger.debug("({}) Check for need to initialize".format(app))
        if app is not None and App.get_repo_url(app) and App.get_repo_branch(
                app):

            # Initializer.
            logger.debug("({}) Preparing to initialize with branch: {}".format(
                app, App.get_repo_branch(app)))
            App.init(app)

        else:

            # Iterate through built apps
            for app in App.get_built_apps():

                # Ensure it's a built app
                if App.get_repo_url(app) and App.get_repo_branch(app):

                    # Initializer.
                    logger.debug("({}) Preparing to initialize".format(app))
                    App.init(app)
Exemplo n.º 2
0
    def run(self):

        # Create a list of apps to update
        apps = App.get_apps()

        # Get the app.
        app = self.options.get("<app>")
        if app:
            apps = [app]

        # Filter out apps without repository details
        apps = [app for app in apps if App.get_repo_branch(app)]

        # Ensure no local changes
        if Stack.run(
            ["git", "diff-index", "--name-status", "--exit-code", "HEAD"]):
            logger.error(
                "Current working copy has changes, cannot update app repositories"
            )
            exit(1)

        logger.info("Will update {}".format(", ".join(apps)))

        # Iterate and update
        for app in apps:

            # Get the repo URL
            repo_url = App.get_repo_url(app)
            branch = App.get_repo_branch(app)
            if repo_url is None or branch is None:
                logger.error(
                    "({}) No repository URL and/or branch specified...".format(
                        app))
                continue

            # Determine the path to the app directory
            apps_dir = os.path.relpath(Stack.get_config("apps-directory"))
            subdir = os.path.join(apps_dir, app)

            # Check for pre-checkout hook
            Stack.hook("pre-checkout", app, [os.path.realpath(subdir)])

            # Build the command
            command = [
                "git",
                "subtree",
                "add",
                "--prefix={}".format(subdir),
                repo_url,
                branch,
                "--squash",
            ]

            # Remove the current subtree.
            Stack.run(["git", "rm", "-rf", subdir])
            Stack.run(["rm", "-rf", subdir])
            Stack.run([
                "git",
                "commit",
                "-m",
                '"Stack op: Removing subtree {} for cloning branch {}"'.format(
                    app, branch),
            ])

            # Run the command.
            Stack.run(command)

            # Check for post-checkout hook
            Stack.hook("post-checkout", app, [os.path.realpath(subdir)])