2 represent a git branch..
5 Does repo require branching? - flag in config?
6 ** list of repo's ?? with ability to turn on/off
8 Start editing without branch?
9 -> show prompt to start branch
10 -> flag a ticket? optional ??
12 Once editing branch...
13 -> merge with squash / ticket...
14 ** show list of repo's with 'working' branches?
15 ** select some/all to merge with a issue fix..
17 ?? closing ticket in system ??
20 need to push all? / fetch all?
28 public class GitBranch : Object
32 public bool active = false;
33 public string lastrev = "";
34 public string name = "";
35 public bool is_remote;
36 public string remote = "";
37 public string remoterev = "";
38 public string age = "";
42 public string toString()
45 "active: " + (active ? "true" : "false") + "\n" +
46 "is_remote: " + (is_remote ? "true" : "false") + "\n" +
47 "lastrev: " + lastrev + "\n" +
48 "name: " + name + "\n" +
49 "remote: " + remote + "\n" +
50 "remoterev: " + remoterev + "\n" +
51 "age: " + age + "\n" ;
55 public GitBranch(GitRepo repo)
63 public static void loadBranches(GitRepo repo)
65 repo.branches = new Gee.HashMap<string,GitBranch>();
67 var branches = new Gee.HashMap<string,GitBranch>();
68 var local = new Gee.HashMap<string,GitBranch>();
69 var remotes = new Gee.HashMap<string,GitBranch>();
72 this.repo.repo.loadLocalBranches();
73 this.loadRemoteHeads();
76 // repo.git( { "fetch", "-a" } ); == done async before...
78 string[] cmd = { "branch", "--no-color", "--verbose", "--no-abbrev" , "-a" };
79 var res = repo.git( cmd );
80 var lines = res.split("\n");
81 for (var i = 0; i < lines.length ; i++) {
82 var br = new GitBranch(repo);
83 if (!br.parseBranchListItem(lines[i])) {
86 GLib.debug("add branch %s", br.realName());
88 local.set(br.name, br);
90 remotes.set(br.remote, br);
93 branches.set(br.realName(), br);
95 repo.currentBranch = br;
101 "--format", "%(refname:short):remotes/%(upstream:short):remotes/%(authordate:relative)",
105 foreach(var line in bl) {
106 if (line.length < 1) continue;
108 var ar = line.split(":remotes/");
110 var rname = "remotes/" + ar[1];
114 // we should always have a local version of it.
115 if (branches.has_key(lname)) {
116 branches.get(lname).remote = rname;
117 branches.get(lname).age = ar[2];
120 if (!branches.has_key(rname) || !branches.has_key(lname) ) {
123 branches.get(lname).remoterev = branches.get(rname).lastrev;
124 // flag it for not adding..
126 branches.get(rname).name = lname;
128 foreach(var br in branches.values) {
129 GLib.debug("BRANCH:\n%s\n" , br.toString());
130 if (br.name.length > 0 || ! /^remotes\/origin\//.match(br.remote)) {
131 GLib.debug("SKIP - track exists");
134 var newname = br.remote.replace("remotes/origin/","");
135 if (branches.has_key(newname)) {
136 GLib.debug("SKIP - have branch already");
141 repo.git( { "branch" ,"--track" , newname, "origin/" + newname} );
144 local.set(br.name, br);
148 this bit of the code tries to turn a local branch into a track of a remote one.
149 -- that's probably not a good idea.
150 var r_replace = new Regex("^remotes/");
151 var o_replace = new Regex("^origin/");
152 foreach(var r in remotes.values) {
153 if (r.name.length >0) {
156 var name = r_replace.replace(r.name, r.name.length,0, "");
157 name = o_replace.replace(name, name.length,0, "");
158 name = name.replace("/", ".");
162 repo.branches = local;
169 public bool parseBranchListItem(string str)
171 if (str.length < 1) {
174 this.active = str[0] == '*';
176 var parts = Regex.split_simple ("[ \t]+", str.substring(2).strip());
177 if (parts[1] == "->") { // it's an alias.. eg. remotes/origin/HEAD -> origin/master..
180 this.is_remote = false;
181 this.lastrev = parts[1];
182 if (parts[0].has_prefix("remotes/")) {
183 this.is_remote = true;
184 this.remote = parts[0];
186 this.name = parts[0];
190 public string realName()
192 return this.is_remote ? this.remote : this.name;