git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org, "David Kågedal" <davidk@lysator.liu.se>
Subject: [StGit PATCH] Emacs mode: automatically cd up to root of worktree
Date: Wed, 14 May 2008 03:49:09 +0200	[thread overview]
Message-ID: <20080514014820.7140.28591.stgit@yoghurt> (raw)
In-Reply-To: <20080514014309.GA17955@diana.vm.bytemark.co.uk>

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@winehq.org>.

Signed-off-by: Karl Hasselström <kha@treskal.com>

---

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))

  parent reply	other threads:[~2008-05-14  1:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-14  1:43 StGit: kha/{safe,experimental} updated Karl Hasselström
2008-05-14  1:44 ` [StGit PATCH 1/2] Import version to a separate namespace Karl Hasselström
2008-05-14  1:47 ` [StGit PATCH 2/2] Better StGit version tracking Karl Hasselström
2008-05-14  1:49 ` Karl Hasselström [this message]
2008-05-14  7:38   ` [StGit PATCH] Emacs mode: automatically cd up to root of worktree David Kågedal
2008-05-14  8:13     ` Karl Hasselström
2008-05-14  1:49 ` [StGit PATCH] New command: stg redo Karl Hasselström
2008-05-19 21:21 ` StGit: kha/{safe,experimental} updated Catalin Marinas
2008-05-20  7:04   ` Karl Hasselström
2008-05-20 17:19     ` Catalin Marinas
2008-05-20 21:02       ` Karl Hasselström
2008-05-20 21:39         ` [StGit PATCH] Try the built-in version string before git-describe Karl Hasselström
2008-05-21 14:38           ` Catalin Marinas
2008-05-21 15:00             ` Karl Hasselström
2008-05-21 14:07         ` StGit: kha/{safe,experimental} updated Catalin Marinas
2008-05-21 14:58           ` Karl Hasselström

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080514014820.7140.28591.stgit@yoghurt \
    --to=kha@treskal.com \
    --cc=catalin.marinas@gmail.com \
    --cc=davidk@lysator.liu.se \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).