import os
import pprint
import sys

import git_util


def main(argv):
    # repo path
    if 1 < len(argv):
        repo_path = argv[1]
    else:
        # default
        repo_path = os.getcwd()

    remotes_list = get_remote_list_from_git_remote(repo_path)
    print(remotes_list)

    branch_remote_list = get_remote_branch_list(repo_path)
    print(branch_remote_list)

    remote_branch_dict = organize_remote_branch_dict(branch_remote_list)

    pprint.pprint(remote_branch_dict)


def organize_remote_branch_dict(git_branch_r_list):
    remote_branch_dict = {}

    for remote_branch_name_str in git_branch_r_list:
        remote_name, branch_name = remote_branch_name_str.split('/', maxsplit=1)
        remote_branch_dict[remote_name] = remote_branch_dict.get(remote_name, []) + [branch_name]

    return remote_branch_dict


def get_remote_branch_list(repo_path):
    branch_remotes_str = git_path('branch -r', repo_path)
    branch_remote_list = splitlines_strip(branch_remotes_str)
    return tuple(branch_remote_list)


def splitlines_strip(string):
    result_list = [line.strip() for line in string.splitlines()]
    return result_list


def get_remote_list_from_git_remote(repo_path=os.getcwd()):
    # make git run on a given path
    remotes_str = git_path('remote', repo_path)

    return tuple(splitlines_strip(remotes_str))


def git_path(cmd, repo_path=os.getcwd()):
    git_path_spec = "-C '%s'" % repo_path
    git_result_str = git_util.git(' '.join((git_path_spec, cmd)))
    return git_result_str


if __name__ == '__main__':
    main(sys.argv)

@@ -273,24 +273,134 @@
 otes_list)%0A%0A
+    remote_set = set(remotes_list)%0A%0A    if 1 %3C len(remote_set):%0A        if 'upstream' in remote_set:%0A%0A        
     branch_r
@@ -438,32 +438,40 @@
 list(repo_path)%0A
+        
     print(branch
@@ -477,32 +477,40 @@
 h_remote_list)%0A%0A
+        
     remote_branc
@@ -563,24 +563,32 @@
 mote_list)%0A%0A
+        
     pprint.p
@@ -610,24 +610,694 @@
 anch_dict)%0A%0A
+            if 'upstream' in remote_branch_dict:%0A                origin_branch_set = set(remote_branch_dict%5B'origin'%5D)%0A                upstream_branch_set = set(remote_branch_dict%5B'upstream'%5D)%0A                upstream_branch_set.remove('HEAD')%0A%0A                delta_set = upstream_branch_set - origin_branch_set%0A%0A                print('delta_set =')%0A                pprint.pprint(delta_set)%0A%0A        else:%0A            ValueError('upstream not in remote : %25r' %25 remote_set)%0A    elif 1 == len(remote_set):%0A        print('only one remote')%0A    elif 0 == len(remote_set):%0A        print('no remote')%0A    else:%0A        raise ValueError('# repository = %25r' %25 len(remote_set))%0A
 %0Adef organiz

make delta set