[gitg/wip/commit] Stub out commit procedure
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/wip/commit] Stub out commit procedure
- Date: Thu, 4 Jul 2013 08:33:54 +0000 (UTC)
commit a591d4cfca4b18ed57a2093991fb8e381a9925ed
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Thu Jul 4 10:28:06 2013 +0200
Stub out commit procedure
gitg/commit/gitg-commit-dialog.vala | 16 ++++++
gitg/commit/gitg-commit.vala | 26 +++++++++-
gitg/resources/ui/gitg-commit-dialog.ui | 2 +-
libgitg/gitg-stage.vala | 86 +++++++++++++++++++++++++++++++
4 files changed, 128 insertions(+), 2 deletions(-)
---
diff --git a/gitg/commit/gitg-commit-dialog.vala b/gitg/commit/gitg-commit-dialog.vala
index 2bee445..8727bb5 100644
--- a/gitg/commit/gitg-commit-dialog.vala
+++ b/gitg/commit/gitg-commit-dialog.vala
@@ -29,6 +29,12 @@ class Dialog : Gtk.Dialog
[GtkChild (name = "ok-button")]
private Gtk.Button d_button_ok;
+ [GtkChild (name = "check_button_amend")]
+ private Gtk.CheckButton d_check_button_amend;
+
+ [GtkChild (name = "check_button_sign_off")]
+ private Gtk.CheckButton d_check_button_sign_off;
+
private Settings d_fontsettings;
public GtkSource.View source_view_message
@@ -50,6 +56,16 @@ class Dialog : Gtk.Dialog
}
}
+ public bool amend
+ {
+ get { return d_check_button_amend.active; }
+ }
+
+ public bool sign_off
+ {
+ get { return d_check_button_sign_off.active; }
+ }
+
construct
{
d_fontsettings = new Settings("org.gnome.desktop.interface");
diff --git a/gitg/commit/gitg-commit.vala b/gitg/commit/gitg-commit.vala
index 500e5a6..83d7dde 100644
--- a/gitg/commit/gitg-commit.vala
+++ b/gitg/commit/gitg-commit.vala
@@ -386,7 +386,31 @@ namespace GitgCommit
private void do_commit(Dialog dlg)
{
-
+ var stage = application.repository.stage;
+
+ Gitg.StageCommitOptions opts = 0;
+
+ if (dlg.amend)
+ {
+ opts |= Gitg.StageCommitOptions.AMEND;
+ }
+
+ if (dlg.sign_off)
+ {
+ opts |= Gitg.StageCommitOptions.SIGN_OFF;
+ }
+
+ stage.commit.begin(dlg.message, opts, (obj, res) => {
+ try
+ {
+ var o = stage.commit.end(res);
+ }
+ catch (Error e)
+ {
+ var msg = _("Failed to commit");
+ application.show_infobar(msg, e.message, Gtk.MessageType.ERROR);
+ }
+ });
}
private void on_commit_clicked()
diff --git a/gitg/resources/ui/gitg-commit-dialog.ui b/gitg/resources/ui/gitg-commit-dialog.ui
index 7b66400..d54a0d3 100644
--- a/gitg/resources/ui/gitg-commit-dialog.ui
+++ b/gitg/resources/ui/gitg-commit-dialog.ui
@@ -107,7 +107,7 @@
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="check_button_signoff">
+ <object class="GtkCheckButton" id="check_button_sign_off">
<property name="label" translatable="yes">Add signed-off-by signature</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
diff --git a/libgitg/gitg-stage.vala b/libgitg/gitg-stage.vala
index 1331bf5..e6b2741 100644
--- a/libgitg/gitg-stage.vala
+++ b/libgitg/gitg-stage.vala
@@ -20,6 +20,14 @@
namespace Gitg
{
+[Flags]
+public enum StageCommitOptions
+{
+ NONE = 0,
+ SIGN_OFF = 1 << 0,
+ AMEND = 1 << 1
+}
+
public class Stage : Object
{
private weak Repository d_repository;
@@ -122,6 +130,84 @@ public class Stage : Object
});
}
+ private string message_with_sign_off(Ggit.Config conf, string message) throws Error
+ {
+ string? user;
+ string? email;
+
+ user = conf.get_string("user.name");
+ email = conf.get_string("user.email");
+
+ if (user != null && email != null)
+ {
+ return "%s\nSigned-off-by: %s <%s>\n".printf(message, user, email);
+ }
+ else
+ {
+ return message;
+ }
+ }
+
+ private string convert_message_to_encoding(Ggit.Config conf, string message)
+ {
+ string? encoding;
+
+ try
+ {
+ encoding = conf.get_string("i18n.commitencoding");
+ }
+ catch
+ {
+ return message;
+ }
+
+ if (encoding != null &&
+ encoding != "" &&
+ encoding.ascii_casecmp("UTF-8") != 0)
+ {
+ try
+ {
+ return convert(message, -1, encoding, "UTF-8");
+ }
+ catch {}
+ }
+
+ return message;
+ }
+
+ public async Ggit.OId commit(string message,
+ StageCommitOptions options) throws Error
+ {
+ yield thread_index((index) => {
+ // TODO: run pre-commit hook
+
+ // Write tree from index
+ var tree = index.write_tree();
+
+ // TODO: write COMMIT_EDITMSG and run commit-msg hook
+
+ var conf = d_repository.get_config();
+ conf.refresh();
+
+ string emsg = message;
+
+ if ((options & StageCommitOptions.SIGN_OFF) != 0)
+ {
+ emsg = message_with_sign_off(conf, emsg);
+ }
+
+ emsg = convert_message_to_encoding(conf, emsg);
+
+ // TODO: commit
+
+ // TODO: update ref with subject of message
+
+ // TODO: run post-commit hook
+ });
+
+ return null;
+ }
+
/**
* Revert index changes.
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]