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 = "";
40 Ggit.RemoteHead[] remote_heads = null;
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)
60 public void loadRemoteHeads(bool force = false)
63 if (!force && this.remote_heads != null) {
66 var r = this.repo.lookup_remote("origin");
67 r.connect(Ggit.Direction.FETCH, this.callbacks, null, null);
68 this.remote_heads = r.list();
74 public static void loadBranches(GitRepo repo)
76 repo.branches = new Gee.HashMap<string,GitBranch>();
78 var branches = new Gee.HashMap<string,GitBranch>();
79 var local = new Gee.HashMap<string,GitBranch>();
80 var remotes = new Gee.HashMap<string,GitBranch>();
83 this.loadLocalBranches();
84 this.loadRemoteHeads();
87 // repo.git( { "fetch", "-a" } ); == done async before...
89 string[] cmd = { "branch", "--no-color", "--verbose", "--no-abbrev" , "-a" };
90 var res = repo.git( cmd );
91 var lines = res.split("\n");
92 for (var i = 0; i < lines.length ; i++) {
93 var br = new GitBranch(repo);
94 if (!br.parseBranchListItem(lines[i])) {
97 GLib.debug("add branch %s", br.realName());
99 local.set(br.name, br);
101 remotes.set(br.remote, br);
104 branches.set(br.realName(), br);
106 repo.currentBranch = br;
112 "--format", "%(refname:short):remotes/%(upstream:short):remotes/%(authordate:relative)",
116 foreach(var line in bl) {
117 if (line.length < 1) continue;
119 var ar = line.split(":remotes/");
121 var rname = "remotes/" + ar[1];
125 // we should always have a local version of it.
126 if (branches.has_key(lname)) {
127 branches.get(lname).remote = rname;
128 branches.get(lname).age = ar[2];
131 if (!branches.has_key(rname) || !branches.has_key(lname) ) {
134 branches.get(lname).remoterev = branches.get(rname).lastrev;
135 // flag it for not adding..
137 branches.get(rname).name = lname;
139 foreach(var br in branches.values) {
140 GLib.debug("BRANCH:\n%s\n" , br.toString());
141 if (br.name.length > 0 || ! /^remotes\/origin\//.match(br.remote)) {
142 GLib.debug("SKIP - track exists");
145 var newname = br.remote.replace("remotes/origin/","");
146 if (branches.has_key(newname)) {
147 GLib.debug("SKIP - have branch already");
152 repo.git( { "branch" ,"--track" , newname, "origin/" + newname} );
155 local.set(br.name, br);
159 this bit of the code tries to turn a local branch into a track of a remote one.
160 -- that's probably not a good idea.
161 var r_replace = new Regex("^remotes/");
162 var o_replace = new Regex("^origin/");
163 foreach(var r in remotes.values) {
164 if (r.name.length >0) {
167 var name = r_replace.replace(r.name, r.name.length,0, "");
168 name = o_replace.replace(name, name.length,0, "");
169 name = name.replace("/", ".");
173 repo.branches = local;
180 public bool parseBranchListItem(string str)
182 if (str.length < 1) {
185 this.active = str[0] == '*';
187 var parts = Regex.split_simple ("[ \t]+", str.substring(2).strip());
188 if (parts[1] == "->") { // it's an alias.. eg. remotes/origin/HEAD -> origin/master..
191 this.is_remote = false;
192 this.lastrev = parts[1];
193 if (parts[0].has_prefix("remotes/")) {
194 this.is_remote = true;
195 this.remote = parts[0];
197 this.name = parts[0];
201 public string realName()
203 return this.is_remote ? this.remote : this.name;