[StGit PATCH] Emacs mode: automatically cd up to root of worktree

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

 



git's emacs mode automatically finds the root of the worktree, so that
the user doesn't have to. Teach StGit's emacs mode the same trick by
borrowing the git-get-top-dir function from git.

The borrowed code was written by Alexandre Julliard <julliard@xxxxxxxxxx>.

Signed-off-by: Karl Hasselström <kha@xxxxxxxxxxx>

---

David, would you sanity check this for me?

 contrib/stgit.el |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)


diff --git a/contrib/stgit.el b/contrib/stgit.el
index 339ef13..2a6fee3 100644
--- a/contrib/stgit.el
+++ b/contrib/stgit.el
@@ -12,9 +12,20 @@
 (defun stgit (dir)
   "Manage stgit patches"
   (interactive "DDirectory: \n")
-  (switch-to-stgit-buffer dir)
+  (switch-to-stgit-buffer (git-get-top-dir dir))
   (stgit-refresh))
 
+(defun git-get-top-dir (dir)
+  "Retrieve the top-level directory of a git tree."
+  (let ((cdup (with-output-to-string
+                (with-current-buffer standard-output
+                  (cd dir)
+                  (unless (eq 0 (call-process "git" nil t nil
+                                              "rev-parse" "--show-cdup"))
+                    (error "cannot find top-level git tree for %s." dir))))))
+    (expand-file-name (concat (file-name-as-directory dir)
+                              (car (split-string cdup "\n"))))))
+
 (defun switch-to-stgit-buffer (dir)
   "Switch to a (possibly new) buffer displaying StGit patches for DIR"
   (setq dir (file-name-as-directory dir))

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux