From f93028e569039b48af6351e2d37f80d15d94ff5a Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Mon, 5 Nov 2018 15:28:53 +0800 Subject: [PATCH] handling of old branches --- GitMonitor.vala | 26 +++------- GitMonitorQueue.vala | 4 +- GitRepo.vala | 73 +++++++++++++++++++--------- Makefile.am | 3 +- MergeBranch.bjs | 2 +- NewBranch.bjs | 6 +-- NewBranch.vala | 15 +++--- RooTicket.vala | 2 +- StatusIcon.vala | 113 ++++++++++++++++++++++++++++++++----------- config1.builder | 3 +- 10 files changed, 159 insertions(+), 88 deletions(-) diff --git a/GitMonitor.vala b/GitMonitor.vala index 78663103..543ba589 100644 --- a/GitMonitor.vala +++ b/GitMonitor.vala @@ -594,10 +594,8 @@ public class GitMonitor : Monitor cmd = new GitMonitorQueue(src); cmd.action = "commit"; cmd.message = cmd.vname; - this.queue.add(cmd); - - - + this.queue.append_val(cmd); + } public override void onDeleted(MonitorNamePathDir src) @@ -622,10 +620,7 @@ public class GitMonitor : Monitor cmd.message = cmd.vname; cmd.commit_all = true; - this.queue.add(cmd); - - - + this.queue.append_val(cmd); } public override void onCreated(MonitorNamePathDir src) { @@ -681,9 +676,7 @@ public class GitMonitor : Monitor cmd = new GitMonitorQueue(src); cmd.action = "commit"; cmd.message = "Attribute changed " + cmd.vname; - this.queue.add(cmd); - - + this.queue.append_val(cmd); } public override void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest) @@ -737,14 +730,9 @@ public class GitMonitor : Monitor cmd.message = cmd_d.vname; } - - this.queue.add(cmd); - - // this is where it get's complicated... - // as we might be moving across repo's... - - - + this.queue.append_val(cmd); + + } diff --git a/GitMonitorQueue.vala b/GitMonitorQueue.vala index 00ab4655..1988d4f8 100644 --- a/GitMonitorQueue.vala +++ b/GitMonitorQueue.vala @@ -119,8 +119,8 @@ public class GitMonitorQueue : MonitorNamePathDir { } public static string messageToString(Gee.ArrayList messages ) { string[] ret = {}; - for(var i =0; i < messages.size; i++) { - ret+= messages.get(i).message; + for(var i =0; i < messages.length; i++) { + ret+= messages.index(i).message; } return string.joinv("\n",ret); } diff --git a/GitRepo.vala b/GitRepo.vala index b1bb25f9..17556aed 100644 --- a/GitRepo.vala +++ b/GitRepo.vala @@ -347,33 +347,60 @@ public class GitRepo : Object } public bool createBranchNamed(string branchname) - { - - try { + { + + if (this.branches.has_key(branchname)) { // this is where it get's tricky... - - string[] cmd = { "ls-files" , "-m" }; // list the modified files.. - var ret = this.git(cmd); - var stash = ret.length> 1 ; - - - cmd = { "stash" }; - if (stash) { this.git(cmd); } - - cmd = { "checkout", branchname }; - this.git(cmd); - - cmd = { "merge", "master" }; - this.git(cmd); - - cmd = { "stash", "pop" }; - if (stash) { this.git(cmd); } - + try { + string[] cmd = { "ls-files" , "-m" }; // list the modified files.. + var ret = this.git(cmd); + var stash = ret.length> 1 ; + + + cmd = { "stash" }; + if (stash) { this.git(cmd); } + + cmd = { "checkout", branchname }; + this.git(cmd); + } catch(Error e) { + GitMonitor.gitmonitor.pauseError(e.message); + return false; + + } + try { + cmd = { "merge", "master" }; + this.git(cmd); + } catch(Error e) { + try { + cmd = { "mergetool" }; + this.git(cmd); + cmd = { "commit" "-m" "Fix merge conflicts from master" }; + this.git(cmd); + } catch(Error ee) { + GitMonitor.gitmonitor.pauseError(ee.message); + return false; + } + } + try { + cmd = { "stash", "pop" }; + if (stash) { this.git(cmd); } + } catch(Error ee) { + GitMonitor.gitmonitor.pauseError(ee.message); + return false; + } + } else { - string[] cmd = { "checkout", "-b" , branchname }; - this.git(cmd); + try { + + string[] cmd = { "checkout", "-b" , branchname }; + this.git(cmd); + } catch(Error ee) { + GitMonitor.gitmonitor.pauseError(ee.message); + return false; + } + } var notification = new Notify.Notification( "Changed to branch %s".printf(branchname), diff --git a/Makefile.am b/Makefile.am index 6cc2b4a0..0137963f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -30,7 +30,8 @@ Gitlive_SOURCES = \ c/xorg_idletime.c \ WindowLog.vala \ Clones.vala \ - NewBranch.vala + NewBranch.vala \ + MergeBranch.vala diff --git a/MergeBranch.bjs b/MergeBranch.bjs index f57dd66d..2fa6f417 100644 --- a/MergeBranch.bjs +++ b/MergeBranch.bjs @@ -154,4 +154,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/NewBranch.bjs b/NewBranch.bjs index 6af4ae29..958fd87f 100644 --- a/NewBranch.bjs +++ b/NewBranch.bjs @@ -9,8 +9,8 @@ "items" : [ { "listeners" : { - "delete_event" : "(self, event) => {\n this.el.hide();\n this.running = false;\n return true; \n //test \n}\n ", - "response" : " (self, response_id) => { \n \n\tGLib.debug(\"got %d\", (int) response_id);\n\tif (response_id == 0) {\n\t _this.el.hide();\t\n\t this.running = false; \n\t\tGitMonitor.gitmonitor.start();\t \n\t \treturn;\n\t}\n\t \n\t// have they selected a ticket..\n\t// make that the current active ticket?\n\t// we really need to store locally what ticket is being worked on..\n\t// in theory we could be working on multiple project and not merging..\n\t// -- each repo would have their active ticket (only one per repo)\n\t// -- so we could just store that in there\n\t// -- initial load can check the contents of the ticket files on first scan.\n\tvar ticket_id = _this.ticketsel.selectedTicketId();\n\t\n\tvar success = true;\n if (this.repo != null) {\n \tvar bn = _this.name.el.get_text();\n \tif (ticket_id != \"\" ) {\n\t\t\tsuccess = this.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);\n\t\t} else {\n\t\t\tsuccess = this.repo.createBranchNamed(bn);\n\t\t}\n }\n if (success) {\n\t\tGitMonitor.gitmonitor.restoreQueue( this.queue );\n\t\tGitMonitor.gitmonitor.runQueue(); \n\t\tGitMonitor.gitmonitor.start();\n\t}\n this.running = false; \t \n\t_this.el.hide();\n\t \n\t \n}", + "delete_event" : "(self, event) => {\n this.el.hide();\n return true; \n //test \n}\n ", + "response" : " (self, response_id) => { \n \n\tGLib.debug(\"got %d\", (int) response_id);\n\tif (response_id == 0) {\n\t _this.el.hide();\t\n\t this.running = false; \n\t \treturn;\n\t}\n\t \n\t// have they selected a ticket..\n\t// make that the current active ticket?\n\t// we really need to store locally what ticket is being worked on..\n\t// in theory we could be working on multiple project and not merging..\n\t// -- each repo would have their active ticket (only one per repo)\n\t// -- so we could just store that in there\n\t// -- initial load can check the contents of the ticket files on first scan.\n\tvar ticket_id = _this.ticketsel.selectedTicketId();\n\t\n if (this.repo != null) {\n \tvar bn = _this.name.el.get_text();\n \tif (ticket_id != \"\" ) {\n\t\t\tthis.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);\n\t\t} else {\n\t\t\tthis.repo.createBranchNamed(bn);\n\t\t}\n }\n\n\t\t this.running = false; \n\n\t \n\t \n\t \n\n\t \n}", "show" : "(self) => {\n \n\n //test\n}" }, "default_width" : 500, @@ -115,4 +115,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/NewBranch.vala b/NewBranch.vala index 99733f45..1ec03eea 100644 --- a/NewBranch.vala +++ b/NewBranch.vala @@ -84,15 +84,14 @@ public class NewBranch : Object success = this.repo.createBranchNamed(bn); } } - if (success) { - GitMonitor.gitmonitor.restoreQueue( this.queue ); - GitMonitor.gitmonitor.runQueue(); - GitMonitor.gitmonitor.start(); - } - this.running = false; - _this.el.hide(); + + this.running = false; + + + + + - }); this.el.show.connect( (self) => { diff --git a/RooTicket.vala b/RooTicket.vala index 5ddbeae1..604d435d 100644 --- a/RooTicket.vala +++ b/RooTicket.vala @@ -253,4 +253,4 @@ public class RooTicket : Object - } \ No newline at end of file + } diff --git a/StatusIcon.vala b/StatusIcon.vala index 64199105..137d7504 100644 --- a/StatusIcon.vala +++ b/StatusIcon.vala @@ -53,11 +53,11 @@ public class StatusIconA : StatusIcon { this.set_name("gitlive"); this.set_visible(true); - var menu = new MenuA(); + var menu = new GitliveMenu(); menu.ref(); this.button_press_event.connect( ( ev ) =>{ print("button press event called\n"); - + menu.updateMerges(); menu.show_all(); if (this.paused) { @@ -86,6 +86,7 @@ public class StatusIconA : StatusIcon { //print(Array.prototype.slice.call(arguments).join(',')); print("menu activiate called\n"); + menu.updateMerges(); //var menu = this.get('menu'); menu.show_all(); @@ -157,31 +158,85 @@ public class StatusIconA : StatusIcon { } - class MenuA : Gtk.Menu + class GitliveMenu : Gtk.Menu { public ImageMenuItem pause; public ImageMenuItem resume; + public Gtk.MenuItem before_seperator; + public Gtk.MenuItem after_seperator; + - public MenuA() + public GitliveMenu() { - this.pause = new ImageMenuItemA(); + this.pause = new MenuItemPause(); this.append(this.pause); - this.resume = new ImageMenuItemB(); + this.resume = new MenuItemStartCommits(); this.append(this.resume); - this.append(new ImageMenuItemC()); - this.append(new ImageMenuItemD()); - this.append(new ImageMenuItemE()); - this.append(new ImageMenuItemF()); - this.append(new ImageMenuItemG()); - - - + this.append(new MenuItemPullAll()); + this.before_seperator = new Gtk.SeparatorMenuItem(); + this.append(this.before_seperator); + + this.after_seperator = new Gtk.SeparatorMenuItem(); + this.append(this.after_seperator); + //this.append(new MenuItemUpdateTimesheet()); + this.append(new MenuItemManageClones()); + this.append(new MenuItemAbout()); + this.append(new MenuItemQuit()); + this.merge_items = new Gee.ArrayList(); } + public Gee.ArrayList merge_items; - class ImageMenuItemA : ImageMenuItem { + public void updateMerges() + { + // show a list of possible merges on the menu. + foreach (var m in this.merge_items) { + this.remove(m); + } + foreach(var r in GitRepo.singleton().cache.values ) { + GLib.debug("checking %s for branch = %s", r.name, r.currentBranch.name); + if (!r.is_wip_branch()) { + continue; + } + GLib.debug("checking for activeTicket"); + var t = r.activeTicket; + if (t == null) { + continue; + } + var mi = new MergeMenuItem(r,t); + this.insert (mi,4); //backwards. + this.merge_items.add(mi); + + } + + } + + + class MergeMenuItem : Gtk.MenuItem { + + GitRepo repo; + RooTicket ticket; + + public MergeMenuItem(GitRepo r, RooTicket t) + { + this.repo = r; + this.ticket = t; + + this.label = ("Merge [%s] #%s %s".printf(r.name, t.id , t.summary)); + + this.activate.connect(() => { + MergeBranch.singleton().show(this.ticket); + // show merge dialog.. + }); + + } + + } + + + class MenuItemPause : ImageMenuItem { - public ImageMenuItemA() + public MenuItemPause() { //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE ); @@ -207,9 +262,9 @@ public class StatusIconA : StatusIcon { } - class ImageMenuItemB : ImageMenuItem { + class MenuItemStartCommits : ImageMenuItem { - public ImageMenuItemB() + public MenuItemStartCommits() { var image = new Gtk.Image(); @@ -235,9 +290,9 @@ public class StatusIconA : StatusIcon { } - class ImageMenuItemC : ImageMenuItem { + class MenuItemPullAll : ImageMenuItem { - public ImageMenuItemC() + public MenuItemPullAll() { var image = new Gtk.Image(); @@ -371,14 +426,14 @@ public class StatusIconA : StatusIcon { } - class ImageMenuItemD : ImageMenuItem { + class MenuItemUpdateTimesheet : ImageMenuItem { - public ImageMenuItemD() + public MenuItemUpdateTimesheet() { var image = new Gtk.Image(); image.set_from_stock(Gtk.Stock.SAVE,Gtk.IconSize.MENU ); - this.set_image (image); + this.set_image (image); this.label= "Update Timesheet"; this.always_show_image = true; this.accel_group = null; @@ -391,9 +446,9 @@ public class StatusIconA : StatusIcon { } - class ImageMenuItemE : ImageMenuItem { + class MenuItemManageClones : ImageMenuItem { - public ImageMenuItemE() + public MenuItemManageClones() { var image = new Gtk.Image(); @@ -411,9 +466,9 @@ public class StatusIconA : StatusIcon { } - class ImageMenuItemF : ImageMenuItem { + class MenuItemAbout : ImageMenuItem { - public ImageMenuItemF() + public MenuItemAbout() { var image = new Gtk.Image(); @@ -441,9 +496,9 @@ public class StatusIconA : StatusIcon { } - class ImageMenuItemG : ImageMenuItem { + class MenuItemQuit : ImageMenuItem { - public ImageMenuItemG() + public MenuItemQuit() { var image = new Gtk.Image(); diff --git a/config1.builder b/config1.builder index c5e4bc99..55088b03 100644 --- a/config1.builder +++ b/config1.builder @@ -17,7 +17,8 @@ "..//gitlive/GitBranch.vala", "..//gitlive/NewBranch.vala", "..//gitlive/GitMonitorQueue.vala", - "..//gitlive/RooTicket.vala" + "..//gitlive/RooTicket.vala", + "..//gitlive/MergeBranch.vala" ], "packages" : [ ] -- 2.39.2