[gitg/wip/commit] Properly update reflog after commit



commit 674844f3c59c0f65f6d49fcb7da583a3d6475741
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Fri Jul 5 15:46:00 2013 +0200

    Properly update reflog after commit

 libgitg/gitg-stage.vala |   40 ++++++++++++++++++++++++++++++++++++----
 1 files changed, 36 insertions(+), 4 deletions(-)
---
diff --git a/libgitg/gitg-stage.vala b/libgitg/gitg-stage.vala
index d1ddada..39e6a47 100644
--- a/libgitg/gitg-stage.vala
+++ b/libgitg/gitg-stage.vala
@@ -369,7 +369,11 @@ public class Stage : Object
                        }
 
                        var treeoid = index.write_tree();
-                       var head = d_repository.get_head();
+
+                       // Note: get the symbolic ref here
+                       var head = d_repository.lookup_reference("HEAD");
+
+                       // Resolve the ref and get the actual target id
                        var headoid = head.resolve().get_target();
 
                        ret = d_repository.create_commit_from_oids("HEAD",
@@ -380,12 +384,40 @@ public class Stage : Object
                                                                   treeoid,
                                                                   new Ggit.OId[] { headoid });
 
-                       if (head.has_reflog())
+                       bool always_update = false;
+
+                       try
+                       {
+                               always_update = conf.get_bool("core.logAllRefUpdates");
+                       } catch {}
+
+                       var reflogmsg = "commit: " + get_subject(message);
+
+                       // Update reflog of HEAD
+                       try
+                       {
+                               if (always_update || head.has_reflog())
+                               {
+                                       var reflog = head.get_reflog();
+                                       reflog.append(ret, committer, reflogmsg);
+                                       reflog.write();
+                               }
+                       } catch {}
+
+                       if (head.get_reference_type() == Ggit.RefType.SYMBOLIC)
                        {
-                               // Update reflog
+                               // Update reflog of whereever HEAD points to
                                try
                                {
-                                       head.create_reflog(ret, committer, get_subject(message));
+                                       var resolved = head.resolve();
+
+                                       if (always_update || resolved.has_reflog())
+                                       {
+                                               var reflog = resolved.get_reflog();
+
+                                               reflog.append(ret, committer, reflogmsg);
+                                               reflog.write();
+                                       }
                                } catch {}
                        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]