summaryrefslogtreecommitdiffstats
path: root/gum
diff options
context:
space:
mode:
authorAdrian Likins <alikins@grimlock.devel.redhat.com>2008-08-05 17:40:35 -0400
committerAdrian Likins <alikins@grimlock.devel.redhat.com>2008-08-05 17:40:35 -0400
commit1a92458de0cc1e594ef5fdc292d8c322902db7fe (patch)
treeee2f8d21daa7db658d3be9d323a63ba48729baf2 /gum
parent148ebb6e7b4c370cdfbbfeed1de88741ceac6f5f (diff)
downloadfunc-1a92458de0cc1e594ef5fdc292d8c322902db7fe.tar.gz
func-1a92458de0cc1e594ef5fdc292d8c322902db7fe.tar.xz
func-1a92458de0cc1e594ef5fdc292d8c322902db7fe.zip
- add method for checking existing git config
- refactor existing config parser - change find_remote_branches to expect a single name and to return a list - add find_remotes_branches to expect a list of names and to return a hash of lists - add show_remote_branches instead of doing it in find_remote_branches - add_remote checks for existes of branches and remotes - add_remote adds all the remote branches as local branches in format "repo_name-remote_branch_name"
Diffstat (limited to 'gum')
-rwxr-xr-x[-rw-r--r--]gum120
1 files changed, 84 insertions, 36 deletions
diff --git a/gum b/gum
index 7f1e57a..241157f 100644..100755
--- a/gum
+++ b/gum
@@ -34,12 +34,17 @@ class Repos(object):
remotes = {}
def __init__(self):
self.remotes = {}
- self.parse_config()
-
-
-
- def parse_config(self, filename="gum.config"):
- cmd = "git-config --file %s --get-regexp 'remote\..*\.url'" % filename
+ self.local_config = {}
+ self.parse_config(filename="gum.config",
+ config=self.remotes)
+ self.parse_config(filename=".git/config",
+ config=self.local_config)
+
+ def parse_config(self, filename=None, config={}):
+ file_arg = ""
+ if filename:
+ file_arg = "--file %s" % filename
+ cmd = "git-config %s --get-regexp 'remote\..*\.url'" % file_arg
p = subprocess.Popen(cmd, shell=True,
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
output = p.communicate()
@@ -49,41 +54,85 @@ class Repos(object):
(name_blurb, url) = line.split()
# uh yeah, this should be a regex of something.
name = name_blurb.split('.')[1]
- self.remotes[name] = url
+ config[name] = url
- def find_remote_branches(self, names):
+ def find_remote_branches(self, name):
+ remote_branches = []
+ branches_cmd = "git-ls-remote -h %s" % self.remotes[name]
+ p = subprocess.Popen(branches_cmd, shell=True,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ output = p.communicate()[0]
+ # print "output", output
+ branch_names = output.splitlines()
+ for branch_name_bits in branch_names:
+ # print branch_name
+ bits = branch_name_bits.split()
+ # print bits
+ # it's not really a path, but it looks enough like it
+ branch_name = os.path.basename(bits[1])
+ # print "name: %s branch_name %s" % (name, branch_name)
+ # print branch_name
+ remote_branches.append(branch_name)
+
+ return remote_branches
+
+ def find_remotes_branches(self, names):
+ remote_branches = {}
for name in names:
- branches_cmd = "git-ls-remote -h %s" % name
- p = subprocess.Popen(branches_cmd, shell=True,
- stdin=subprocess.PIPE, stdout=subprocess.PIPE)
- output = p.communicate()[0]
- print "output", output
- branch_names = output.splitlines()
- for branch_name_bits in branch_names:
-# print branch_name
- bits = branch_name_bits.split()
-# print bits
- # it's not really a path, but it looks enough like it
- branch_name = os.path.basename(bits[1])
- print "name: %s branch_name %s" % (name, branch_name)
-# print branch_name
-
- # print branch_name
+ branches = self.find_remote_branches(name)
+ for branch in branches:
+ if not remote_branches.has_key(name):
+ remote_branches[name] = []
+ remote_branches[name].append(branch)
+
+ return remote_branches
+
+ def show_remote_branches(self):
+ branches = self.find_remotes_branches(self.names())
+
+ for repo in branches.keys():
+ for branch in branches[repo]:
+ print "%s/%s" % (repo, branch)
+
+ # see if we are already cofigured for a remote
+ def remote_exists(self, name):
+ if self.local_config.has_key(name):
+ print "remote exists", name
+ return True
+ return False
+
+ # see if we are already configure for a branch
+ def branch_exists(self, name):
+ pass
def add_remote(self, names):
+ print "add_remote", names
for name in names:
- add_cmd = "git remote add %s %s" % (name, self.remotes[name])
- p = subprocess.Popen(add_cmd, shell=True,
- stdin=subprocess.PIPE, stdout=subprocess.PIPE)
- output = p.communicate()
+ if not self.remote_exists(name):
+ print "name", name, "self.remotes[name]", self.remotes[name]
+ add_cmd = "git remote add %s %s" % (name, self.remotes[name])
+ p = subprocess.Popen(add_cmd, shell=True,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ output = p.communicate()
- fetch_cmd = "git fetch %s" % name
- p = subprocess.Popen(fetch_cmd, shell=True,
- stdin=subprocess.PIPE, stdout=subprocess.PIPE)
- output = p.communicate()
+ fetch_cmd = "git fetch %s" % name
+ p = subprocess.Popen(fetch_cmd, shell=True,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ output = p.communicate()
+ else:
+ print "%s is already added to the local git config" % name
-# branches = self.find_remote_branches(name)
+ branches = self.find_remote_branches(name)
+ print "add_remote branches", branches
+
+ for branch in branches:
+ add_branch_cmd = "echo git checkout -b %s-%s %s/%s " % (name, branch, name, branch)
+ p = subprocess.Popen(add_branch_cmd, shell=True,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ output = p.communicate()
+ print add_branch_cmd, output
+
@@ -91,7 +140,6 @@ class Repos(object):
for name in self.remotes.keys():
print name, self.remotes[name]
-
def names(self):
return self.remotes.keys()
@@ -154,7 +202,6 @@ def main(args):
if options.add:
repos.add_remote(args)
-
if options.add_all:
repos.add_remote(repos.names())
@@ -162,7 +209,8 @@ def main(args):
repos.list_remotes()
if options.list_remote_branches:
- repos.find_remote_branches(repos.names())
+ repos.show_remote_branches()
+# repos.find_remote_branches(repos.names())
if __name__ == "__main__":
main(sys.argv)