Example #1
0
File: git.py Project: GaretJax/pm
    def print_status(self):
        status = self.project.status()

        branch_line = status.splitlines()[0]

        clean = True

        if " M " in status or " D " in status:
            red_print("Uncommitted changes")
            clean = False

        if "ahead" in branch_line and "behind" in branch_line:
            if not clean:
                print(" - ", end="")
            red_print("Diverged with remote")
            clean = False

        elif " [ahead" in branch_line:
            if not clean:
                print(" - ", end="")
            red_print("Ahead of remote")
            clean = False

        elif " [behind" in branch_line:
            if not clean:
                print(" - ", end="")
            red_print("Behind remote")
            clean = False

        if clean:
            green_print("Clean")
Example #2
0
File: base.py Project: GaretJax/pm
def status(args=None):
    projects = list_projects(False, args.dir)

    if args.parallel_fetch and not args.fetch:
        print("Warning: -p has no effect without -f")

    if args.parallel_fetch and not args.j:
        print("Warning: -p has no effect without -j")

    if args.fetch:
        print("Fetch in progres...")

    if args.j:
        pool = Pool(args.j)

        def worker(p):
            p.cache(args.submodule)

            if args.parallel_fetch:
                p.fetch_all()

                if args.submodule:
                    p.fetch_submodules()

        for p in projects:
            pool.apply_async(worker, (p,))

        pool.close()
        pool.join()

    if args.fetch and not (args.j and args.parallel_fetch):
        for p in projects:
            p.fetch_all()

            if args.submodule:
                p.fetch_submodules()

    if args.fetch:
        print("Fetch done")

    for p in projects:
        print(p.name)

        print("    ", end="")

        blue_print("{0:<30s}".format(p.branch()))

        p.print_status()

        print("")

        if args.submodule:
            for sub in p.subprojects():
                print_subproject(p, sub, " ")

        for branch in p.branches():
            if branch == p.branch():
                continue

            print("    ", end="")

            cyan_print("{0:<30s}".format(branch))

            remote_branch = "origin/" + branch

            if not p.remote_branch_exist(remote_branch):
                red_print("No remote branch {}".format(remote_branch))
            else:
                local_hash = p.hash(branch)
                remote_hash = p.hash(remote_branch)

                if local_hash == remote_hash:
                    green_print("Clean")
                else:
                    red_print("{} not in sync with {}"
                              .format(branch, remote_branch))

            print("")

        print("")
Example #3
0
File: git.py Project: GaretJax/pm
    def print_submodule_status(self, sub):
        status = self.project.submodule_status(sub)

        branch_line = status.splitlines()[0]

        clean = True

        if " M " in status or " D " in status:
            red_print("Uncommitted changes")
            clean = False

        if "(no branch)" in branch_line:
            if not clean:
                print(" - ", end="")

            clean = False

            path = self.sub_folder(sub)

            branch_name = self.find_detached_source_branch(path)

            if not branch_name:
                red_print("Detached (unable to find source")
            else:
                red_print("Detached (from {})".format(branch_name))

                remote_branch = "remotes/" + branch_name

                if self.remote_branch_exist_f(path, remote_branch):
                    print(" - ", end="")
                    red_print("No remote branch {}".format(remote_branch))
                else:
                    local_hash = self.hash_f(path, "HEAD")
                    remote_hash = self.hash_f(path, remote_branch)

                    if local_hash == remote_hash:
                        print(" - ", end="")
                        green_print("In sync")
                    else:
                        print(" - ", end="")
                        red_print("Not in sync with {}".format(remote_branch))

        if "ahead" in branch_line and "behind" in branch_line:
            if not clean:
                print(" - ", end="")
            red_print("Diverged with remote")
            clean = False

        elif " [ahead" in branch_line:
            if not clean:
                print(" - ", end="")
            red_print("Ahead of remote")
            clean = False

        elif " [behind" in branch_line:
            if not clean:
                print(" - ", end="")
            red_print("Behind remote")
            clean = False

        if clean:
            green_print("Clean")