From 01d58d4385bed77eb5c3002cf937a2c5f60f2156 Mon Sep 17 00:00:00 2001 From: Hannu Koivisto Date: Fri, 8 Jan 2010 20:32:56 +0200 Subject: [PATCH 1/5] Fix magit-log-edit-mode keymap definition and activation. Rely on the standard define-derived-mode functionality. --- magit.el | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/magit.el b/magit.el index cb9d38f1..ff33f7c0 100644 --- a/magit.el +++ b/magit.el @@ -2586,7 +2586,7 @@ branch." ;;; Log edit mode -(defvar magit-log-edit-map +(defvar magit-log-edit-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "C-c C-c") 'magit-log-edit-commit) (define-key map (kbd "C-c C-a") 'magit-log-edit-toggle-amending) @@ -2612,8 +2612,7 @@ Prefix arg means justify as well." (define-derived-mode magit-log-edit-mode text-mode "Magit Log Edit" (set (make-local-variable 'fill-paragraph-function) - 'magit-log-fill-paragraph) - (use-local-map magit-log-edit-map)) + 'magit-log-fill-paragraph)) (defun magit-log-edit-cleanup () (save-excursion From 6a1bb4f644cb0ac19ecfc9e01bf30966c5b4651d Mon Sep 17 00:00:00 2001 From: Hannu Koivisto Date: Wed, 14 Oct 2009 21:28:07 +0300 Subject: [PATCH 2/5] Fix magit-get-top-dir from ruining paths with symlinks. One might argue that this also makes it work better in a case when GIT_DIR points outside of a work tree, but because in that case any directory is a valid "top dir" from GIT's point of view, that is debatable. But at least one can use Magit in that case by first making sure that default-directory is the top dir and then executing magit-status. --- magit.el | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/magit.el b/magit.el index ff33f7c0..f47356e5 100644 --- a/magit.el +++ b/magit.el @@ -401,13 +401,11 @@ Many Magit faces inherit from this one by default." (defun magit-get-top-dir (cwd) (let ((cwd (expand-file-name cwd))) - (and (file-directory-p cwd) - (let* ((default-directory cwd) - (magit-dir - (magit-git-string "rev-parse" "--git-dir"))) - (and magit-dir - (file-name-as-directory - (or (file-name-directory magit-dir) cwd))))))) + (when (file-directory-p cwd) + (let* ((default-directory cwd) + (cdup (magit-git-string "rev-parse" "--show-cdup"))) + (when cdup + (file-name-as-directory (expand-file-name cdup cwd))))))) (defun magit-get-ref (ref) (magit-git-string "symbolic-ref" "-q" ref)) From 94ca78a86fc90a180ba3f9abb89f0c5fc5fdda31 Mon Sep 17 00:00:00 2001 From: Hannu Koivisto Date: Sat, 24 Oct 2009 03:28:45 +0300 Subject: [PATCH 3/5] Add command magit-goto-parent-section. --- magit.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/magit.el b/magit.el index f47356e5..cc202e5d 100644 --- a/magit.el +++ b/magit.el @@ -799,6 +799,12 @@ Many Magit faces inherit from this one by default." (magit-show-commit (or prev section))) (goto-char (magit-section-beginning (or prev section)))))))) +(defun magit-goto-parent-section () + (interactive) + (let ((parent (magit-section-parent (magit-current-section)))) + (when parent + (goto-char (magit-section-beginning parent))))) + (defun magit-goto-section (path) (let ((sec (magit-find-section path magit-top-section))) (if sec @@ -1235,6 +1241,7 @@ Many Magit faces inherit from this one by default." (define-key map (kbd "M-H") 'magit-show-only-files-all) (define-key map (kbd "M-s") 'magit-show-level-4) (define-key map (kbd "M-S") 'magit-show-level-4-all) + (define-key map (kbd "") 'magit-goto-parent-section) (define-key map (kbd "g") 'magit-refresh) (define-key map (kbd "G") 'magit-refresh-all) (define-key map (kbd "s") 'magit-stage-item) From 8020b0396a9e6d0883385f1ef6e99df7b34cb704 Mon Sep 17 00:00:00 2001 From: Hannu Koivisto Date: Sat, 24 Oct 2009 03:33:26 +0300 Subject: [PATCH 4/5] Add command magit-toggle-file-section. For those who never want to toggle at hunk granularity. --- magit.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/magit.el b/magit.el index cc202e5d..2bc69548 100644 --- a/magit.el +++ b/magit.el @@ -881,6 +881,13 @@ Many Magit faces inherit from this one by default." (interactive) (magit-section-hideshow #'magit-section-expand)) +(defun magit-toggle-file-section () + "Like `magit-toggle-section' but toggles at file granularity." + (interactive) + (when (eq 'hunk (first (magit-section-context-type (magit-current-section)))) + (magit-goto-parent-section)) + (magit-toggle-section)) + (defun magit-toggle-section () (interactive) (magit-section-hideshow From ea0812f119d820b8dff9183258e1001d69b12b9b Mon Sep 17 00:00:00 2001 From: Hannu Koivisto Date: Sat, 24 Oct 2009 19:57:01 +0300 Subject: [PATCH 5/5] Add command magit-reset-head-hard. Intended to be bound to X instead of magit-reset-working-tree for those who feel it is a more consistent pair for x. Suggests HEAD and therefore works like magit-reset-working-tree by default. Eliminates need to use C-u x. --- magit.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/magit.el b/magit.el index 2bc69548..fb321f67 100644 --- a/magit.el +++ b/magit.el @@ -2418,10 +2418,16 @@ branch." (magit-run-git "reset" (if hard "--hard" "--soft") (magit-rev-to-git rev)))) +(defun magit-reset-head-hard (rev) + (interactive (list (magit-read-rev (format "Hard reset head to") + (or (magit-default-rev) + "HEAD")))) + (magit-reset-head rev t)) + (defun magit-reset-working-tree () (interactive) - (if (yes-or-no-p "Discard all uncommitted changes? ") - (magit-run-git "reset" "--hard"))) + (when (yes-or-no-p "Discard all uncommitted changes? ") + (magit-reset-head-hard "HEAD"))) ;;; Rewriting