Beispiel #1
0
    def merge_local_tracking_branches(self):
        logger.info('Merging local tracking branches')

        save_commit = Git.get_checked_out_commit(self.path)

        # checkout current branch in case repo has just been cloned and workdir
        # is empty
        if not Git.repo_is_clean(self.path):
            if save_commit in self.branches:
                self.branches[save_commit].cmd_checkout()

        stashed = False
        if not Git.repo_is_clean(self.path):
            if Git.stash(self.path):
                ioutils.inform('Repo is dirty, stashed at %s' % save_commit, minor=True)
                stashed = True

        for branch in self.branches.values():
            if branch.tracking:
                if not branch.cmd_merge(branch.tracking):
                    ioutils.complain('Merge failed at %s of %s/%s' %
                                     (branch.name, branch.tracking.remote.name,
                                      branch.tracking.name), minor=True)

        if Git.checkout(self.path, save_commit):
            if stashed and Git.stash(self.path, apply=True):
                ioutils.inform('Restored stash at %s' % save_commit, minor=True)
Beispiel #2
0
    def cmd_merge(self):
        ioutils.inform('Merging %s' % self.path)

        # Check branch heartbeats after fetch
        Branch.check_heartbeats(self)

        # Branch post process
        self.check_for_stale_local_tracking_branches()
        self.setup_local_tracking_branches()

        # Merge locals
        self.merge_local_tracking_branches()
Beispiel #3
0
    def cmd_merge(self):
        ioutils.inform('Merging %s' % self.path)

        # Check branch heartbeats after fetch
        Branch.check_heartbeats(self)

        # Branch post process
        self.check_for_stale_local_tracking_branches()
        self.setup_local_tracking_branches()

        # Merge locals
        self.merge_local_tracking_branches()
Beispiel #4
0
    def cmd_compact(self, check=True):
        ioutils.inform('Checking for compactness: %s' % self.path)

        def do_check(output_always=False):
            is_compact, output = Git.check_compactness_local(self.path)
            if not is_compact or output_always:
                ioutils.output(output)
            return is_compact

        is_compact = do_check()
        if not check and not is_compact:
            ioutils.inform('Trying to compact', minor=True)
            Git.compact_local(self.path)
            do_check(output_always=True)
Beispiel #5
0
    def cmd_compact(self, check=True):
        ioutils.inform('Checking for compactness: %s' % self.path)

        def do_check(output_always=False):
            is_compact, output = Git.check_compactness_local(self.path)
            if not is_compact or output_always:
                ioutils.output(output)
            return is_compact

        is_compact = do_check()
        if not check and not is_compact:
            ioutils.inform('Trying to compact', minor=True)
            Git.compact_local(self.path)
            do_check(output_always=True)
Beispiel #6
0
    def cmd_fetch(self):
        ioutils.inform('Fetching %s' % self.path)

        if not os.path.exists(self.path):
            self.do_init_repo()

        success = True
        self.set_remotes_in_checkout()
        self.detect_branches(update_tracking=True)
        for remote in self.remotes.values():
            success = success and remote.cmd_fetch()
        self.detect_branches(only_remote=True)

        if not success:
            ioutils.complain('Failed fetching %s' % self.path)
        return success
Beispiel #7
0
    def setup_local_tracking_branches(self):
        logger.info('Setting up local tracking branches')

        remote = Remote.get_canonical_remote(self)
        for branch in remote.branches_tracking.values():
            if not branch.tracked_by:
                local_branch = self.branches.get(branch.name, None)
                if local_branch:
                    ioutils.inform('Setting local branch %s to track %s/%s' %
                                   (branch.name, branch.remote.name,
                                    branch.name), minor=True)
                    local_branch.cmd_set_tracking(branch)
                else:
                    ioutils.inform('Setting up local tracking branch %s' %
                                   branch.name, minor=True)
                    BranchLocal.cmd_add_tracking(self, branch)
Beispiel #8
0
    def cmd_fetch(self):
        ioutils.inform('Fetching %s' % self.path)

        if not os.path.exists(self.path):
            self.do_init_repo()

        success = True
        self.set_remotes_in_checkout()
        self.detect_branches(update_tracking=True)
        for remote in self.remotes.values():
            success = success and remote.cmd_fetch()
        self.detect_branches(only_remote=True)

        if not success:
            ioutils.complain('Failed fetching %s' % self.path)
        return success
Beispiel #9
0
    def setup_local_tracking_branches(self):
        logger.info('Setting up local tracking branches')

        remote = Remote.get_canonical_remote(self)
        for branch in remote.branches_tracking.values():
            if not branch.tracked_by:
                local_branch = self.branches.get(branch.name, None)
                if local_branch:
                    ioutils.inform(
                        'Setting local branch %s to track %s/%s' %
                        (branch.name, branch.remote.name, branch.name),
                        minor=True)
                    local_branch.cmd_set_tracking(branch)
                else:
                    ioutils.inform('Setting up local tracking branch %s' %
                                   branch.name,
                                   minor=True)
                    BranchLocal.cmd_add_tracking(self, branch)
Beispiel #10
0
 def cmd_merge(self, branch):
     longname = StrFmt.fmt_branch_remote_tracking(branch.remote.name, branch.name)
     if Git.commit_is_ahead_of(self.repo.path, self.name, longname):
         ioutils.suggest('Branch %s is ahead of %s, is pushable' %
                         (self.name, longname), minor=True)
         return True
     else:
         if self.cmd_checkout():
             remoted = StrFmt.fmt_branch_remote_tracking(branch.remote.name,
                                                         branch.name)
             merge_ok, output = Git.merge(self.repo.path, remoted)
             if merge_ok:
                 if output:
                     ioutils.inform('Merged %s on %s' % (longname, self.name),
                                    minor=True)
                     ioutils.output(output)
                 return True
             else:
                 Git.reset_hard(self.repo.path, self.name)
Beispiel #11
0
    def merge_local_tracking_branches(self):
        logger.info('Merging local tracking branches')

        save_commit = Git.get_checked_out_commit(self.path)
        if save_commit is None:
            ioutils.complain('Failed to get last commit for %s' % self.path)
            return

        # checkout current branch in case repo has just been cloned and workdir
        # is empty
        if not Git.repo_is_clean(self.path):
            if save_commit in self.branches:
                self.branches[save_commit].cmd_checkout()

        # if the workdir is not clean we will stash it first
        stashed = False
        if not Git.repo_is_clean(self.path):
            if Git.stash(self.path):
                ioutils.inform('Repo is dirty, stashed at %s' % save_commit,
                               minor=True)
                stashed = True

        # merge all tracking branches
        for branch in self.branches.values():
            if branch.tracking:
                if not branch.cmd_merge(branch.tracking):
                    ioutils.complain('Merge failed at %s of %s/%s' %
                                     (branch.name, branch.tracking.remote.name,
                                      branch.tracking.name),
                                     minor=True)

        # check out the "current branch" again - so we end on the same branch
        # checked out as we had in the beginning
        if save_commit in self.branches:
            self.branches[save_commit].cmd_checkout()

        # apply the stash back onto the workdir (could create a conflict)
        if Git.checkout(self.path, save_commit):
            if stashed and Git.stash(self.path, apply=True):
                ioutils.inform('Restored stash at %s' % save_commit,
                               minor=True)
Beispiel #12
0
 def cmd_merge(self, branch):
     longname = StrFmt.fmt_branch_remote_tracking(branch.remote.name,
                                                  branch.name)
     if Git.commit_is_ahead_of(self.repo.path, self.name, longname):
         ioutils.suggest('Branch %s is ahead of %s, is pushable' %
                         (self.name, longname),
                         minor=True)
         return True
     else:
         if self.cmd_checkout():
             remoted = StrFmt.fmt_branch_remote_tracking(
                 branch.remote.name, branch.name)
             merge_ok, output = Git.merge(self.repo.path, remoted)
             if merge_ok:
                 if output:
                     ioutils.inform('Merged %s on %s' %
                                    (longname, self.name),
                                    minor=True)
                     ioutils.output(output)
                 return True
             else:
                 Git.reset_hard(self.repo.path, self.name)
Beispiel #13
0
    def merge_local_tracking_branches(self):
        logger.info('Merging local tracking branches')

        save_commit = Git.get_checked_out_commit(self.path)
        if save_commit is None:
            ioutils.complain('Failed to get last commit for %s' % self.path)
            return

        # checkout current branch in case repo has just been cloned and workdir
        # is empty
        if not Git.repo_is_clean(self.path):
            if save_commit in self.branches:
                self.branches[save_commit].cmd_checkout()

        # if the workdir is not clean we will stash it first
        stashed = False
        if not Git.repo_is_clean(self.path):
            if Git.stash(self.path):
                ioutils.inform('Repo is dirty, stashed at %s' % save_commit, minor=True)
                stashed = True

        # merge all tracking branches
        for branch in self.branches.values():
            if branch.tracking:
                if not branch.cmd_merge(branch.tracking):
                    ioutils.complain('Merge failed at %s of %s/%s' %
                                     (branch.name, branch.tracking.remote.name,
                                      branch.tracking.name), minor=True)

        # check out the "current branch" again - so we end on the same branch
        # checked out as we had in the beginning
        if save_commit in self.branches:
            self.branches[save_commit].cmd_checkout()

        # apply the stash back onto the workdir (could create a conflict)
        if Git.checkout(self.path, save_commit):
            if stashed and Git.stash(self.path, apply=True):
                ioutils.inform('Restored stash at %s' % save_commit, minor=True)