2008-08-14 00:07:44 +02:00
|
|
|
;;; magit -- control Git from Emacs.
|
2008-07-31 22:11:46 +02:00
|
|
|
|
|
|
|
;; Copyright (C) 2008 Marius Vollmer
|
2008-08-19 22:43:34 +02:00
|
|
|
;; Copyright (C) 2008 Linh Dang
|
2008-07-31 22:11:46 +02:00
|
|
|
;;
|
2008-08-06 01:41:05 +02:00
|
|
|
;; Magit is free software; you can redistribute it and/or modify it
|
2008-08-05 18:09:47 +02:00
|
|
|
;; under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
;; any later version.
|
2008-07-31 22:11:46 +02:00
|
|
|
;;
|
2008-08-06 01:41:05 +02:00
|
|
|
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
2008-08-05 18:09:47 +02:00
|
|
|
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
|
|
;; License for more details.
|
2008-07-31 22:11:46 +02:00
|
|
|
;;
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to
|
|
|
|
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
;; Boston, MA 02111-1307, USA.
|
|
|
|
|
2008-08-13 04:28:16 +02:00
|
|
|
;;; Commentary
|
2008-07-31 22:11:46 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
;; Invoking the magit-status function will show a buffer with the
|
2008-07-31 22:11:46 +02:00
|
|
|
;; current status of the current git repository and its checkout.
|
|
|
|
;; That buffer offers key bindings for manipulating the status in
|
|
|
|
;; simple ways.
|
|
|
|
;;
|
|
|
|
;; The status buffer mainly shows the difference between the working
|
|
|
|
;; tree and the index, and the difference between the index and the
|
2008-08-04 01:05:02 +02:00
|
|
|
;; current HEAD. You can add individual hunks from the working tree
|
|
|
|
;; to the index, and you can commit the index.
|
2008-08-12 03:31:07 +02:00
|
|
|
;;
|
2008-08-12 03:41:14 +02:00
|
|
|
;; See the Magit User Manual for more information.
|
2008-08-01 13:37:54 +02:00
|
|
|
|
2008-08-03 20:41:24 +02:00
|
|
|
;;; TODO
|
|
|
|
|
2008-08-30 21:44:06 +02:00
|
|
|
;; - Visiting hunks from staged hunks doesn't work since the line
|
|
|
|
;; number don't refer to the working tree. Fix that somehow.
|
|
|
|
;; - 'C' is very unreliable and often makes a mess.
|
|
|
|
;; - Don't try to stage an already staged hunk, etc. It's harmless
|
|
|
|
;; but fails too late now.
|
|
|
|
;; - Author and other extended information in the log-edit buffer.
|
|
|
|
;; - Commit amending.
|
|
|
|
;; - Make staging optional. When there are no staged changes, call
|
|
|
|
;; the "Unstaged changes" section just "Changes" and use "commit -a"
|
|
|
|
;; when committing.
|
2008-08-19 01:06:17 +02:00
|
|
|
;; - Update commit details when using n and p with commits.
|
2008-08-13 04:35:43 +02:00
|
|
|
;; - Tags
|
2008-08-15 20:36:18 +02:00
|
|
|
;; - Equivalent of interactive rebase
|
2008-08-12 16:39:44 +02:00
|
|
|
;; - 'Subsetting', only looking at a subset of all files.
|
2008-08-06 01:44:41 +02:00
|
|
|
;; - Detect and handle renames and copies.
|
2008-08-03 20:41:24 +02:00
|
|
|
|
2008-08-13 05:14:53 +02:00
|
|
|
(require 'cl)
|
|
|
|
(require 'parse-time)
|
|
|
|
|
2008-08-19 22:43:34 +02:00
|
|
|
(defgroup magit nil
|
|
|
|
"Controlling Git from Emacs."
|
|
|
|
:prefix "magit-"
|
|
|
|
:group 'tools)
|
|
|
|
|
2008-08-19 23:55:42 +02:00
|
|
|
(defface magit-header
|
2008-08-19 22:43:34 +02:00
|
|
|
'((t))
|
|
|
|
"Face for generic header lines.
|
|
|
|
|
|
|
|
Many Magit faces inherit from this one by default."
|
|
|
|
:group 'magit)
|
|
|
|
|
2008-08-19 23:55:42 +02:00
|
|
|
(defface magit-section-title
|
|
|
|
'((t :weight bold :inherit magit-header))
|
2008-08-19 22:43:34 +02:00
|
|
|
"Face for section titles."
|
|
|
|
:group 'magit)
|
|
|
|
|
2008-08-19 23:55:42 +02:00
|
|
|
(defface magit-branch
|
|
|
|
'((t :weight bold :inherit magit-header))
|
2008-08-19 22:43:34 +02:00
|
|
|
"Face for the current branch."
|
|
|
|
:group 'magit)
|
|
|
|
|
2008-08-19 23:55:42 +02:00
|
|
|
(defface magit-diff-file-header
|
|
|
|
'((t :inherit magit-header))
|
2008-08-19 22:43:34 +02:00
|
|
|
"Face for diff file header lines."
|
|
|
|
:group 'magit)
|
|
|
|
|
2008-08-19 23:55:42 +02:00
|
|
|
(defface magit-diff-hunk-header
|
|
|
|
'((t :slant italic :inherit magit-header))
|
2008-08-19 22:43:34 +02:00
|
|
|
"Face for diff hunk header lines."
|
|
|
|
:group 'magit)
|
|
|
|
|
2008-08-19 23:55:42 +02:00
|
|
|
(defface magit-diff-add
|
2008-08-19 22:43:34 +02:00
|
|
|
'((((class color) (background light))
|
|
|
|
:foreground "blue1")
|
|
|
|
(((class color) (background dark))
|
|
|
|
:foreground "white"))
|
|
|
|
"Face for lines in a diff that have been added."
|
|
|
|
:group 'magit)
|
|
|
|
|
2008-08-19 23:55:42 +02:00
|
|
|
(defface magit-diff-none
|
2008-08-19 22:43:34 +02:00
|
|
|
'((t))
|
|
|
|
"Face for lines in a diff that are unchanged."
|
|
|
|
:group 'magit)
|
|
|
|
|
2008-08-19 23:55:42 +02:00
|
|
|
(defface magit-diff-del
|
2008-08-19 22:43:34 +02:00
|
|
|
'((((class color) (background light))
|
|
|
|
:foreground "red")
|
|
|
|
(((class color) (background dark))
|
|
|
|
:foreground "OrangeRed"))
|
|
|
|
"Face for lines in a diff that have been deleted."
|
|
|
|
:group 'magit)
|
|
|
|
|
2008-08-19 23:58:34 +02:00
|
|
|
(defface magit-item-highlight
|
2008-08-24 04:37:13 +02:00
|
|
|
'((((class color) (background light))
|
|
|
|
:background "gray95")
|
|
|
|
(((class color) (background dark))
|
|
|
|
:background "dim gray"))
|
2008-08-19 23:58:34 +02:00
|
|
|
"Face for highlighting the current item."
|
|
|
|
:group 'magit)
|
|
|
|
|
2008-08-01 13:37:54 +02:00
|
|
|
;;; Utilities
|
|
|
|
|
2008-08-13 16:25:32 +02:00
|
|
|
(defun magit-goto-line (line)
|
|
|
|
(save-restriction
|
|
|
|
(widen)
|
|
|
|
(goto-char 1)
|
|
|
|
(forward-line (1- line))))
|
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-shell (cmd &rest args)
|
2008-08-01 13:37:54 +02:00
|
|
|
(let ((str (shell-command-to-string (apply 'format cmd args))))
|
|
|
|
(if (string= str "")
|
|
|
|
nil
|
|
|
|
(if (equal (elt str (- (length str) 1)) ?\n)
|
|
|
|
(substring str 0 (- (length str) 1))
|
|
|
|
str))))
|
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-shell-lines (cmd &rest args)
|
2008-08-06 01:21:29 +02:00
|
|
|
(let ((str (shell-command-to-string (apply 'format cmd args))))
|
|
|
|
(if (string= str "")
|
|
|
|
nil
|
2008-08-06 03:13:40 +02:00
|
|
|
(let ((lines (nreverse (split-string str "\n"))))
|
|
|
|
(if (string= (car lines) "")
|
|
|
|
(setq lines (cdr lines)))
|
|
|
|
(nreverse lines)))))
|
|
|
|
|
2008-08-30 23:28:58 +02:00
|
|
|
(defun magit-shell-exit-code (cmd &rest args)
|
|
|
|
(call-process shell-file-name nil nil nil
|
|
|
|
shell-command-switch (apply #'format cmd args)))
|
|
|
|
|
2008-08-06 03:13:40 +02:00
|
|
|
(defun magit-file-lines (file)
|
|
|
|
(if (file-exists-p file)
|
|
|
|
(magit-shell-lines "cat '%s'" file)
|
|
|
|
nil))
|
2008-08-06 01:21:29 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-concat-with-delim (delim seqs)
|
2008-08-03 20:33:25 +02:00
|
|
|
(cond ((null seqs)
|
|
|
|
nil)
|
|
|
|
((null (cdr seqs))
|
|
|
|
(car seqs))
|
|
|
|
(t
|
2008-08-06 01:41:05 +02:00
|
|
|
(concat (car seqs) delim (magit-concat-with-delim delim (cdr seqs))))))
|
2008-08-03 20:33:25 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-get (&rest keys)
|
2008-08-18 21:07:00 +02:00
|
|
|
(magit-shell "git config %s" (magit-concat-with-delim "." keys)))
|
2008-08-03 20:33:25 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-set (val &rest keys)
|
2008-08-04 01:05:02 +02:00
|
|
|
(if val
|
2008-08-18 21:07:00 +02:00
|
|
|
(magit-shell "git config %s %s" (magit-concat-with-delim "." keys) val)
|
|
|
|
(magit-shell "git config --unset %s" (magit-concat-with-delim "." keys))))
|
2008-08-04 01:05:02 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-get-top-dir (cwd)
|
2008-08-01 13:37:54 +02:00
|
|
|
(let* ((cwd (expand-file-name cwd))
|
2008-08-18 21:07:00 +02:00
|
|
|
(magit-dir (magit-shell "cd '%s' && git rev-parse --git-dir 2>/dev/null"
|
2008-08-21 01:19:58 +02:00
|
|
|
cwd)))
|
2008-08-06 01:41:05 +02:00
|
|
|
(if magit-dir
|
|
|
|
(file-name-as-directory (or (file-name-directory magit-dir) cwd))
|
2008-08-01 13:37:54 +02:00
|
|
|
nil)))
|
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-get-ref (ref)
|
2008-08-18 21:07:00 +02:00
|
|
|
(magit-shell "git symbolic-ref -q %s" ref))
|
2008-08-03 20:33:25 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-get-current-branch ()
|
|
|
|
(let* ((head (magit-get-ref "HEAD"))
|
2008-08-03 20:33:25 +02:00
|
|
|
(pos (and head (string-match "^refs/heads/" head))))
|
|
|
|
(if pos
|
|
|
|
(substring head 11)
|
|
|
|
nil)))
|
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-read-top-dir (prefix)
|
|
|
|
(let ((dir (magit-get-top-dir default-directory)))
|
2008-08-12 12:52:16 +02:00
|
|
|
(if (or (not dir) prefix)
|
2008-08-06 01:41:05 +02:00
|
|
|
(magit-get-top-dir (read-directory-name "Git repository: " dir))
|
2008-08-03 20:33:25 +02:00
|
|
|
dir)))
|
2008-08-01 13:37:54 +02:00
|
|
|
|
2008-08-06 03:18:41 +02:00
|
|
|
(defun magit-name-rev (rev)
|
|
|
|
(magit-shell "git name-rev --always --name-only %s" rev))
|
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-put-line-property (prop val)
|
2008-08-19 23:58:34 +02:00
|
|
|
(put-text-property (line-beginning-position) (line-beginning-position 2)
|
2008-08-04 01:05:02 +02:00
|
|
|
prop val))
|
|
|
|
|
2008-08-16 23:37:50 +02:00
|
|
|
;;; Revisions and ranges
|
|
|
|
|
|
|
|
(defun magit-list-interesting-revisions ()
|
|
|
|
(magit-shell-lines "git branch -a | cut -c3-"))
|
|
|
|
|
|
|
|
(defun magit-read-rev (prompt &optional def)
|
2008-08-17 00:40:04 +02:00
|
|
|
(let* ((prompt (if def
|
2008-08-17 01:32:07 +02:00
|
|
|
(format "%s (default %s): " prompt def)
|
2008-08-17 00:40:04 +02:00
|
|
|
(format "%s: " prompt)))
|
|
|
|
(rev (completing-read prompt (magit-list-interesting-revisions)
|
|
|
|
nil nil nil nil def)))
|
2008-08-16 23:37:50 +02:00
|
|
|
(if (string= rev "")
|
|
|
|
nil
|
|
|
|
rev)))
|
|
|
|
|
|
|
|
(defun magit-read-rev-range (op &optional def-beg def-end)
|
|
|
|
(if current-prefix-arg
|
|
|
|
(read-string (format "%s range: " op))
|
2008-08-17 00:40:04 +02:00
|
|
|
(let ((beg (magit-read-rev (format "%s start" op)
|
|
|
|
def-beg)))
|
2008-08-16 23:37:50 +02:00
|
|
|
(if (not beg)
|
|
|
|
nil
|
2008-08-17 00:40:04 +02:00
|
|
|
(let ((end (magit-read-rev (format "%s end" op) def-end)))
|
2008-08-16 23:37:50 +02:00
|
|
|
(cons beg end))))))
|
|
|
|
|
|
|
|
(defun magit-rev-to-git (rev)
|
|
|
|
(or rev
|
|
|
|
(error "No revision specified"))
|
|
|
|
(if (string= rev ".")
|
|
|
|
(or (magit-marked-object)
|
|
|
|
(error "Commit mark not set"))
|
|
|
|
rev))
|
|
|
|
|
|
|
|
(defun magit-rev-range-to-git (range)
|
|
|
|
(or range
|
|
|
|
(error "No revision range specified"))
|
|
|
|
(if (stringp range)
|
|
|
|
range
|
|
|
|
(if (cdr range)
|
|
|
|
(format "%s..%s"
|
|
|
|
(magit-rev-to-git (car range))
|
|
|
|
(magit-rev-to-git (cdr range)))
|
|
|
|
(format "%s" (magit-rev-to-git (car range))))))
|
|
|
|
|
|
|
|
(defun magit-rev-describe (rev)
|
|
|
|
(or rev
|
|
|
|
(error "No revision specified"))
|
|
|
|
(if (string= rev ".")
|
|
|
|
"mark"
|
|
|
|
(magit-name-rev rev)))
|
|
|
|
|
|
|
|
(defun magit-rev-range-describe (range things)
|
|
|
|
(or range
|
|
|
|
(error "No revision range specified"))
|
|
|
|
(if (stringp range)
|
|
|
|
(format "%s in %s" things range)
|
|
|
|
(if (cdr range)
|
|
|
|
(format "%s from %s to %s" things
|
|
|
|
(magit-rev-describe (car range))
|
|
|
|
(magit-rev-describe (cdr range)))
|
|
|
|
(format "%s at %s" things (magit-rev-describe (car range))))))
|
|
|
|
|
2008-08-17 00:37:48 +02:00
|
|
|
(defun magit-default-rev ()
|
|
|
|
(magit-commit-at-point t))
|
|
|
|
|
2008-08-30 23:28:58 +02:00
|
|
|
(defun magit-file-uptodate-p (file)
|
|
|
|
(eq (magit-shell-exit-code "git diff --quiet %s" file) 0))
|
|
|
|
|
2008-08-21 01:19:58 +02:00
|
|
|
;;; Items
|
|
|
|
|
2008-08-30 22:18:27 +02:00
|
|
|
(defvar *magit-item-context* nil)
|
|
|
|
|
2008-08-21 01:19:58 +02:00
|
|
|
(defstruct magit-item
|
2008-08-30 22:18:27 +02:00
|
|
|
type beginning ending context info)
|
2008-08-21 01:19:58 +02:00
|
|
|
|
|
|
|
(defun magit-markup-item (beg end type info &optional active-beg active-end)
|
|
|
|
(let ((item (make-magit-item :type type
|
|
|
|
:beginning beg
|
|
|
|
:ending end
|
2008-08-30 22:18:27 +02:00
|
|
|
:context *magit-item-context*
|
2008-08-21 01:19:58 +02:00
|
|
|
:info info)))
|
|
|
|
(put-text-property (or active-beg beg) (or active-end end)
|
|
|
|
'magit-item item)
|
|
|
|
item))
|
|
|
|
|
|
|
|
(defun magit-get-item ()
|
|
|
|
(get-text-property (point) 'magit-item))
|
|
|
|
|
|
|
|
(defvar magit-highlight-overlay nil)
|
|
|
|
|
|
|
|
(defvar magit-highlighted-item nil)
|
|
|
|
|
|
|
|
(defun magit-highlight-item ()
|
|
|
|
(let ((item (magit-get-item)))
|
|
|
|
(when (not (eq item magit-highlighted-item))
|
|
|
|
(setq magit-highlighted-item item)
|
|
|
|
(if (not magit-highlight-overlay)
|
|
|
|
(let ((ov (make-overlay 1 1)))
|
|
|
|
(overlay-put ov 'face 'magit-item-highlight)
|
|
|
|
(setq magit-highlight-overlay ov)))
|
|
|
|
(if item
|
|
|
|
(move-overlay magit-highlight-overlay
|
|
|
|
(magit-item-beginning item)
|
|
|
|
(magit-item-ending item)
|
|
|
|
(current-buffer))
|
|
|
|
(delete-overlay magit-highlight-overlay)))))
|
|
|
|
|
2008-08-24 01:31:49 +02:00
|
|
|
(defmacro magit-item-case (head &rest body)
|
|
|
|
(declare (indent 1))
|
|
|
|
(let ((item (car head))
|
|
|
|
(info (cadr head))
|
|
|
|
(opname (caddr head)))
|
|
|
|
`(let* ((,item (magit-get-item))
|
|
|
|
(,info (and ,item (magit-item-info ,item))))
|
|
|
|
(case (and ,item (magit-item-type ,item))
|
|
|
|
,@body
|
|
|
|
,@(if opname
|
|
|
|
`(((nil)
|
|
|
|
(error "Nothing to %s here." ,opname))
|
|
|
|
(t
|
|
|
|
(error "Can't %s a %s." ,opname
|
|
|
|
(let ((type (magit-item-type ,item)))
|
|
|
|
(or (get type 'magit-description)
|
|
|
|
type))))))))))
|
2008-08-24 04:21:36 +02:00
|
|
|
|
2008-08-11 00:28:35 +02:00
|
|
|
;;; Sections
|
|
|
|
|
2008-08-24 04:21:36 +02:00
|
|
|
;; Sections give a tree structure to the buffer content. They are
|
|
|
|
;; used to navigate and for showing/hiding parts of it.
|
|
|
|
;;
|
|
|
|
;; The section tree is implemented by putting 'magit-section
|
|
|
|
;; properties of the form "(DEPTH ID)" on text regions.
|
|
|
|
|
|
|
|
(defun magit-markup-section (beg end depth seq)
|
|
|
|
(put-text-property beg end 'magit-section (list depth seq)))
|
|
|
|
|
|
|
|
(defun magit-section-mark (p)
|
|
|
|
(get-text-property p 'magit-section))
|
|
|
|
|
|
|
|
(defun magit-section-higher-p (s1 s2)
|
|
|
|
(or (not s2)
|
|
|
|
(< (car s2) (car s1))))
|
|
|
|
|
|
|
|
(defun magit-section-child-p (s1 s2)
|
|
|
|
(and s2
|
|
|
|
(> (car s2) (car s1))))
|
|
|
|
|
|
|
|
(defun magit-section-sibling-or-higher-p (s1 s2)
|
|
|
|
(or (not s2)
|
|
|
|
(< (car s2) (car s1))
|
|
|
|
(and (= (car s2) (car s1))
|
|
|
|
(not (eq (cadr s2) (cadr s1))))))
|
|
|
|
|
|
|
|
(defun magit-section-beginning-position (p)
|
|
|
|
(let ((s1 (magit-section-mark p)))
|
|
|
|
(if (not s1)
|
|
|
|
nil
|
|
|
|
(while (let ((s2 (magit-section-mark (- p 1))))
|
|
|
|
(not (magit-section-sibling-or-higher-p s1 s2)))
|
|
|
|
(setq p (previous-single-property-change p 'magit-section
|
|
|
|
nil (point-min))))
|
|
|
|
p)))
|
|
|
|
|
|
|
|
(defun magit-section-ending-position (p)
|
|
|
|
(let ((s1 (magit-section-mark p)))
|
|
|
|
(if (not s1)
|
|
|
|
nil
|
|
|
|
(while (let ((s2 (magit-section-mark p)))
|
|
|
|
(not (magit-section-sibling-or-higher-p s1 s2)))
|
|
|
|
(setq p (next-single-property-change p 'magit-section
|
|
|
|
nil (point-max))))
|
|
|
|
p)))
|
|
|
|
|
|
|
|
(defun magit-section-parent-position (p)
|
|
|
|
(let ((s1 (magit-section-mark p)))
|
|
|
|
(if (not s1)
|
|
|
|
nil
|
|
|
|
(while (and p
|
|
|
|
(let ((s2 (magit-section-mark p)))
|
|
|
|
(not (magit-section-higher-p s1 s2))))
|
|
|
|
(setq p (previous-single-property-change p 'magit-section)))
|
|
|
|
(and p
|
|
|
|
(magit-section-beginning-position p)))))
|
|
|
|
|
|
|
|
(defun magit-section-first-child-position (p)
|
|
|
|
(let ((s1 (magit-section-mark p)))
|
|
|
|
(if (not s1)
|
|
|
|
nil
|
|
|
|
(while (and p
|
|
|
|
(let ((s2 (magit-section-mark p)))
|
|
|
|
(not (magit-section-child-p s1 s2))))
|
|
|
|
(setq p (next-single-property-change p 'magit-section)))
|
|
|
|
p)))
|
2008-08-24 04:28:38 +02:00
|
|
|
|
2008-08-24 04:21:36 +02:00
|
|
|
(defun magit-search-section-forward (section-mark)
|
|
|
|
(let ((p (point)))
|
|
|
|
(while (and p
|
|
|
|
(not (equal section-mark (magit-section-mark p))))
|
|
|
|
(setq p (next-single-property-change p 'magit-section)))
|
|
|
|
(if p
|
|
|
|
(goto-char p)
|
|
|
|
nil)))
|
|
|
|
|
|
|
|
(defun magit-section-at-point ()
|
|
|
|
(do ((p (point) (magit-section-parent-position p))
|
|
|
|
(path nil (cons (cadr (magit-section-mark p)) path)))
|
|
|
|
((not p) path)))
|
|
|
|
|
|
|
|
(defun magit-goto-section (section-path)
|
|
|
|
(let ((goal-pos nil))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(do ((p section-path (cdr p))
|
|
|
|
(d 0 (+ d 1)))
|
|
|
|
((cond ((null p)
|
|
|
|
(setq goal-pos (point))
|
|
|
|
t)
|
|
|
|
(t
|
|
|
|
(not (magit-search-section-forward (list d (car p)))))))))
|
|
|
|
(if goal-pos
|
|
|
|
(goto-char goal-pos))))
|
|
|
|
|
|
|
|
(defun magit-section-hideshow ()
|
|
|
|
(interactive)
|
2008-08-30 21:32:30 +02:00
|
|
|
(let ((beg (save-excursion
|
|
|
|
(goto-char (magit-section-beginning-position (point)))
|
|
|
|
(forward-line)
|
|
|
|
(point)))
|
2008-08-24 04:21:36 +02:00
|
|
|
(end (magit-section-ending-position (point))))
|
|
|
|
(if beg
|
|
|
|
(let ((inhibit-read-only t))
|
|
|
|
(put-text-property beg end
|
|
|
|
'invisible (not (get-text-property
|
|
|
|
beg 'invisible)))))))
|
|
|
|
|
|
|
|
(defun magit-insert-section (id title washer cmd &rest args)
|
|
|
|
(let ((chapter-beg (point)))
|
2008-08-11 00:28:35 +02:00
|
|
|
(if title
|
2008-08-19 23:55:42 +02:00
|
|
|
(insert (propertize title 'face 'magit-section-title) "\n"))
|
2008-08-24 04:21:36 +02:00
|
|
|
(magit-markup-section chapter-beg (point) 0 id)
|
2008-08-11 00:28:35 +02:00
|
|
|
(let* ((beg (point))
|
2008-08-20 22:57:07 +02:00
|
|
|
(status (apply 'call-process cmd nil t nil args)))
|
2008-08-11 00:28:35 +02:00
|
|
|
(if washer
|
|
|
|
(save-restriction
|
|
|
|
(narrow-to-region beg (point))
|
2008-08-30 22:18:27 +02:00
|
|
|
(let ((*magit-item-context* id))
|
|
|
|
(funcall washer status))
|
2008-08-20 22:57:07 +02:00
|
|
|
(goto-char (point-max))))
|
|
|
|
(if (/= beg (point))
|
|
|
|
(insert "\n")
|
2008-08-24 04:21:36 +02:00
|
|
|
(delete-region chapter-beg (point))))))
|
2008-08-11 00:28:35 +02:00
|
|
|
|
2008-08-18 22:51:26 +02:00
|
|
|
(defun magit-next-section ()
|
|
|
|
(interactive)
|
|
|
|
(let ((next-section (next-single-property-change (point)
|
|
|
|
'magit-section)))
|
|
|
|
(if next-section
|
|
|
|
(goto-char next-section)
|
|
|
|
(error "No next section."))))
|
|
|
|
|
|
|
|
(defun magit-previous-section ()
|
|
|
|
(interactive)
|
|
|
|
(let ((prev-section (previous-single-property-change (point)
|
|
|
|
'magit-section)))
|
|
|
|
(if prev-section
|
|
|
|
(goto-char prev-section)
|
|
|
|
(error "No previous section."))))
|
|
|
|
|
2008-08-18 23:42:44 +02:00
|
|
|
(defmacro magit-define-section-jumper (sym title)
|
|
|
|
(let ((fun (intern (format "magit-jump-to-%s" sym)))
|
|
|
|
(doc (format "Jump to section `%s'." title)))
|
|
|
|
`(defun ,fun ()
|
|
|
|
(interactive)
|
|
|
|
(magit-goto-section '(,sym)))))
|
|
|
|
|
2008-08-01 15:04:52 +02:00
|
|
|
;;; Running asynchronous commands
|
|
|
|
|
2008-08-13 16:27:31 +02:00
|
|
|
(defun magit-set-mode-line-process (str)
|
|
|
|
(save-excursion
|
|
|
|
(set-buffer (magit-find-status-buffer))
|
|
|
|
(setq mode-line-process (if str
|
|
|
|
(concat " " str)
|
|
|
|
""))))
|
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defvar magit-process nil)
|
2008-08-01 15:04:52 +02:00
|
|
|
|
2008-08-30 21:34:40 +02:00
|
|
|
(defun magit-run-command (logline cmd &rest args)
|
2008-08-06 01:41:05 +02:00
|
|
|
(or (not magit-process)
|
2008-08-01 15:04:52 +02:00
|
|
|
(error "Git is already running."))
|
|
|
|
(let ((dir default-directory)
|
2008-08-11 04:42:07 +02:00
|
|
|
(buf (get-buffer-create "*magit-process*")))
|
2008-08-13 16:27:31 +02:00
|
|
|
(magit-set-mode-line-process (if (equal cmd "git")
|
|
|
|
(car args)
|
|
|
|
cmd))
|
2008-08-01 15:04:52 +02:00
|
|
|
(save-excursion
|
|
|
|
(set-buffer buf)
|
|
|
|
(setq default-directory dir)
|
|
|
|
(erase-buffer)
|
2008-08-30 21:34:40 +02:00
|
|
|
(insert "$ " logline "\n")
|
2008-08-06 01:41:05 +02:00
|
|
|
(setq magit-process (apply 'start-process "git" buf cmd args))
|
|
|
|
(set-process-sentinel magit-process 'magit-process-sentinel))))
|
2008-08-01 15:04:52 +02:00
|
|
|
|
2008-08-30 21:34:40 +02:00
|
|
|
(defun magit-run (cmd &rest args)
|
|
|
|
(apply #'magit-run-command
|
|
|
|
(magit-concat-with-delim " " (cons cmd args))
|
|
|
|
cmd args))
|
|
|
|
|
|
|
|
(defun magit-run-shell (fmt &rest args)
|
|
|
|
(let ((cmd (apply #'format fmt args)))
|
2008-08-30 23:28:58 +02:00
|
|
|
(magit-run-command cmd shell-file-name shell-command-switch cmd)))
|
2008-08-30 21:34:40 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-revert-files ()
|
|
|
|
(let ((files (magit-shell-lines "git ls-files")))
|
2008-08-06 01:21:29 +02:00
|
|
|
(dolist (file files)
|
|
|
|
(let ((buffer (find-buffer-visiting file)))
|
|
|
|
(when (and buffer
|
|
|
|
(not (verify-visited-file-modtime buffer))
|
|
|
|
(not (buffer-modified-p buffer)))
|
|
|
|
(with-current-buffer buffer
|
|
|
|
(ignore-errors
|
|
|
|
(revert-buffer t t t))))))))
|
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-process-sentinel (process event)
|
2008-08-21 01:34:05 +02:00
|
|
|
(with-current-buffer (process-buffer process)
|
|
|
|
(let ((msg (format "Git %s." (substring event 0 -1))))
|
|
|
|
(insert msg "\n")
|
|
|
|
(message msg)))
|
|
|
|
(setq magit-process nil)
|
2008-08-13 16:27:31 +02:00
|
|
|
(magit-set-mode-line-process nil)
|
2008-08-06 01:41:05 +02:00
|
|
|
(magit-revert-files)
|
2008-08-07 00:49:35 +02:00
|
|
|
(magit-update-status (magit-find-status-buffer)))
|
2008-08-01 15:04:52 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-display-process ()
|
2008-08-03 21:29:08 +02:00
|
|
|
(interactive)
|
2008-08-11 04:42:07 +02:00
|
|
|
(display-buffer "*magit-process*"))
|
2008-08-03 21:29:08 +02:00
|
|
|
|
2008-08-07 00:49:35 +02:00
|
|
|
;;; Mode
|
|
|
|
|
2008-08-18 23:42:44 +02:00
|
|
|
;; We define individual functions (instead of using lambda etc) so
|
|
|
|
;; that the online help can show something meaningful.
|
|
|
|
|
|
|
|
(magit-define-section-jumper untracked "Untracked changes")
|
|
|
|
(magit-define-section-jumper unstaged "Unstaged changes")
|
|
|
|
(magit-define-section-jumper staged "Staged changes")
|
|
|
|
(magit-define-section-jumper unpushed "Unpushed changes")
|
|
|
|
|
2008-08-12 23:33:31 +02:00
|
|
|
(defvar magit-mode-map
|
|
|
|
(let ((map (make-keymap)))
|
2008-08-18 22:51:26 +02:00
|
|
|
(suppress-keymap map t)
|
2008-08-19 01:06:08 +02:00
|
|
|
(define-key map (kbd "n") 'magit-next-section)
|
|
|
|
(define-key map (kbd "p") 'magit-previous-section)
|
2008-08-24 04:21:36 +02:00
|
|
|
(define-key map (kbd "TAB") 'magit-section-hideshow)
|
2008-08-18 23:42:44 +02:00
|
|
|
(define-key map (kbd "1") 'magit-jump-to-untracked)
|
|
|
|
(define-key map (kbd "2") 'magit-jump-to-unstaged)
|
|
|
|
(define-key map (kbd "3") 'magit-jump-to-staged)
|
|
|
|
(define-key map (kbd "4") 'magit-jump-to-unpushed)
|
2008-08-12 23:33:31 +02:00
|
|
|
(define-key map (kbd "g") 'magit-status)
|
2008-08-21 01:19:58 +02:00
|
|
|
(define-key map (kbd "s") 'magit-stage-item)
|
2008-08-12 23:33:31 +02:00
|
|
|
(define-key map (kbd "S") 'magit-stage-all)
|
2008-08-21 01:19:58 +02:00
|
|
|
(define-key map (kbd "u") 'magit-unstage-item)
|
2008-08-20 23:19:15 +02:00
|
|
|
(define-key map (kbd "U") 'magit-unstage-all)
|
2008-08-21 01:19:58 +02:00
|
|
|
(define-key map (kbd "i") 'magit-ignore-item)
|
|
|
|
(define-key map (kbd "?") 'magit-describe-item)
|
|
|
|
(define-key map (kbd ".") 'magit-mark-item)
|
2008-08-14 00:50:50 +02:00
|
|
|
(define-key map (kbd "=") 'magit-diff-with-mark)
|
2008-08-16 23:37:50 +02:00
|
|
|
(define-key map (kbd "l") 'magit-log-head)
|
|
|
|
(define-key map (kbd "L") 'magit-log)
|
2008-08-17 01:35:05 +02:00
|
|
|
(define-key map (kbd "d") 'magit-diff-working-tree)
|
2008-08-16 23:37:50 +02:00
|
|
|
(define-key map (kbd "D") 'magit-diff)
|
2008-08-24 04:28:38 +02:00
|
|
|
(define-key map (kbd "a") 'magit-apply-item)
|
2008-08-30 20:37:01 +02:00
|
|
|
(define-key map (kbd "A") 'magit-cherry-pick)
|
2008-08-24 04:28:38 +02:00
|
|
|
(define-key map (kbd "v") 'magit-revert-item)
|
2008-08-16 23:37:50 +02:00
|
|
|
(define-key map (kbd "x") 'magit-reset-head)
|
|
|
|
(define-key map (kbd "X") 'magit-reset-working-tree)
|
2008-08-21 01:41:43 +02:00
|
|
|
(define-key map (kbd "k") 'magit-discard-item)
|
2008-08-21 01:19:58 +02:00
|
|
|
(define-key map (kbd "RET") 'magit-visit-item)
|
2008-08-24 02:01:29 +02:00
|
|
|
(define-key map (kbd "SPC") 'magit-show-item-or-scroll-up)
|
|
|
|
(define-key map (kbd "DEL") 'magit-show-item-or-scroll-down)
|
2008-08-16 23:37:50 +02:00
|
|
|
(define-key map (kbd "b") 'magit-checkout)
|
2008-08-12 23:33:31 +02:00
|
|
|
(define-key map (kbd "B") 'magit-create-branch)
|
|
|
|
(define-key map (kbd "m") 'magit-manual-merge)
|
|
|
|
(define-key map (kbd "M") 'magit-automatic-merge)
|
2008-08-13 04:28:16 +02:00
|
|
|
(define-key map (kbd "R") 'magit-rebase-step)
|
2008-08-12 23:33:31 +02:00
|
|
|
(define-key map (kbd "P") 'magit-push)
|
2008-08-20 23:18:04 +02:00
|
|
|
(define-key map (kbd "f") 'magit-remote-update)
|
|
|
|
(define-key map (kbd "F") 'magit-pull)
|
2008-08-12 23:33:31 +02:00
|
|
|
(define-key map (kbd "c") 'magit-log-edit)
|
|
|
|
(define-key map (kbd "C") 'magit-add-log)
|
2008-08-19 01:06:08 +02:00
|
|
|
(define-key map (kbd "$") 'magit-display-process)
|
2008-08-20 23:29:50 +02:00
|
|
|
(define-key map (kbd "q") 'quit-window)
|
2008-08-12 23:33:31 +02:00
|
|
|
map))
|
2008-08-07 00:49:35 +02:00
|
|
|
|
2008-08-07 02:02:45 +02:00
|
|
|
(defvar magit-mode-hook nil)
|
|
|
|
|
|
|
|
(put 'magit-mode 'mode-class 'special)
|
|
|
|
|
2008-08-13 05:14:53 +02:00
|
|
|
(defvar magit-marked-object nil)
|
|
|
|
(make-variable-buffer-local 'magit-marked-object)
|
2008-08-17 01:27:00 +02:00
|
|
|
(put 'magit-marked-object 'permanent-local t)
|
|
|
|
|
|
|
|
(defvar magit-submode nil)
|
|
|
|
(make-variable-buffer-local 'magit-submode)
|
|
|
|
(put 'magit-submode 'permanent-local t)
|
2008-08-13 05:14:53 +02:00
|
|
|
|
2008-08-07 00:49:35 +02:00
|
|
|
(defun magit-mode ()
|
|
|
|
"Review the status of a git repository and act on it.
|
2008-08-18 22:13:16 +02:00
|
|
|
|
|
|
|
Please see the manual for a complete description of Magit.
|
2008-08-07 02:02:45 +02:00
|
|
|
|
|
|
|
\\{magit-mode-map}"
|
2008-08-07 00:49:35 +02:00
|
|
|
(kill-all-local-variables)
|
|
|
|
(setq buffer-read-only t)
|
|
|
|
(setq major-mode 'magit-mode
|
2008-08-13 16:27:31 +02:00
|
|
|
mode-name "Magit"
|
2008-08-16 20:52:33 +02:00
|
|
|
mode-line-process ""
|
|
|
|
truncate-lines t)
|
2008-08-19 23:58:34 +02:00
|
|
|
(add-hook 'post-command-hook #'magit-highlight-item nil t)
|
2008-08-07 02:02:45 +02:00
|
|
|
(use-local-map magit-mode-map)
|
|
|
|
(run-mode-hooks 'magit-mode-hook))
|
2008-08-03 21:10:00 +02:00
|
|
|
|
2008-08-17 01:27:00 +02:00
|
|
|
(defun magit-mode-init (dir submode)
|
|
|
|
(setq default-directory dir
|
|
|
|
magit-submode submode)
|
|
|
|
(magit-mode))
|
|
|
|
|
2008-08-01 15:04:52 +02:00
|
|
|
;;; Status
|
|
|
|
|
2008-08-21 01:19:58 +02:00
|
|
|
(defun magit-wash-untracked-files (status)
|
2008-08-04 01:05:02 +02:00
|
|
|
(goto-char (point-min))
|
2008-08-11 00:28:35 +02:00
|
|
|
(let ((seq 0))
|
|
|
|
(while (not (eobp))
|
2008-08-21 01:19:58 +02:00
|
|
|
(let ((filename (buffer-substring-no-properties
|
|
|
|
(point) (line-end-position))))
|
2008-08-20 00:05:21 +02:00
|
|
|
(cond ((not (string= filename ""))
|
2008-08-24 04:21:36 +02:00
|
|
|
(magit-markup-section (line-beginning-position)
|
|
|
|
(line-beginning-position 2)
|
|
|
|
1 seq)
|
2008-08-20 00:05:21 +02:00
|
|
|
(magit-put-line-property 'face '(:foreground "red"))
|
2008-08-21 01:19:58 +02:00
|
|
|
(magit-markup-item (line-beginning-position)
|
|
|
|
(line-beginning-position 2)
|
|
|
|
'untracked-file filename)
|
2008-08-20 00:05:21 +02:00
|
|
|
(setq seq (+ seq 1)))))
|
2008-08-11 00:28:35 +02:00
|
|
|
(forward-line)
|
2008-08-20 00:05:21 +02:00
|
|
|
(beginning-of-line))))
|
2008-08-11 00:28:35 +02:00
|
|
|
|
2008-08-21 01:19:58 +02:00
|
|
|
(defun magit-wash-diff-markup-diff (head-seq head-beg head-end)
|
2008-08-05 00:09:07 +02:00
|
|
|
(let ((head-end (or head-end (point))))
|
|
|
|
(when head-beg
|
2008-08-21 01:19:58 +02:00
|
|
|
(magit-markup-item head-beg (point)
|
|
|
|
'diff nil
|
|
|
|
head-beg head-end)
|
2008-08-24 04:21:36 +02:00
|
|
|
(magit-markup-section head-beg head-end 1 head-seq))))
|
2008-08-21 01:19:58 +02:00
|
|
|
|
|
|
|
(defun magit-hunk-item-head-beg (item)
|
|
|
|
(car (magit-item-info item)))
|
2008-08-05 00:09:07 +02:00
|
|
|
|
2008-08-21 01:19:58 +02:00
|
|
|
(defun magit-hunk-item-head-end (item)
|
|
|
|
(cadr (magit-item-info item)))
|
|
|
|
|
|
|
|
(defun magit-wash-diff-markup-hunk (head-seq hunk-seq
|
2008-08-24 04:28:38 +02:00
|
|
|
head-beg head-end hunk-beg)
|
2008-08-05 00:09:07 +02:00
|
|
|
(when hunk-beg
|
2008-08-21 01:19:58 +02:00
|
|
|
(magit-markup-item hunk-beg (point)
|
|
|
|
'hunk (list head-beg head-end))
|
2008-08-24 04:21:36 +02:00
|
|
|
(magit-markup-section hunk-beg (point) 1 head-seq)
|
|
|
|
(magit-markup-section hunk-beg (point) 2 hunk-seq)))
|
2008-08-04 14:54:08 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-wash-diff (status)
|
2008-08-04 02:26:34 +02:00
|
|
|
(goto-char (point-min))
|
|
|
|
(let ((n-files 1)
|
2008-08-11 00:28:35 +02:00
|
|
|
(head-seq 0)
|
2008-08-04 02:52:16 +02:00
|
|
|
(head-beg nil)
|
|
|
|
(head-end nil)
|
2008-08-11 00:28:35 +02:00
|
|
|
(hunk-seq 0)
|
2008-08-05 00:09:07 +02:00
|
|
|
(hunk-beg nil))
|
2008-08-04 02:26:34 +02:00
|
|
|
(while (not (eobp))
|
|
|
|
(let ((prefix (buffer-substring-no-properties
|
2008-08-11 23:28:28 +02:00
|
|
|
(point) (min (+ (point) n-files) (point-max)))))
|
2008-08-04 02:52:16 +02:00
|
|
|
(cond ((looking-at "^diff")
|
2008-08-19 23:55:42 +02:00
|
|
|
(magit-put-line-property 'face 'magit-diff-file-header)
|
2008-08-21 01:19:58 +02:00
|
|
|
(magit-wash-diff-markup-diff head-seq head-beg head-end)
|
|
|
|
(magit-wash-diff-markup-hunk head-seq hunk-seq
|
|
|
|
head-beg head-end hunk-beg)
|
2008-08-11 00:28:35 +02:00
|
|
|
(setq head-seq (+ head-seq 1))
|
2008-08-04 02:52:16 +02:00
|
|
|
(setq head-beg (point))
|
2008-08-06 14:51:09 +02:00
|
|
|
(setq head-end nil)
|
2008-08-11 00:28:35 +02:00
|
|
|
(setq hunk-seq 0)
|
2008-08-06 14:51:09 +02:00
|
|
|
(setq hunk-beg nil))
|
2008-08-04 02:52:16 +02:00
|
|
|
((looking-at "^@+")
|
2008-08-19 23:55:42 +02:00
|
|
|
(magit-put-line-property 'face 'magit-diff-hunk-header)
|
2008-08-04 02:26:34 +02:00
|
|
|
(setq n-files (- (length (match-string 0)) 1))
|
2008-08-05 00:09:07 +02:00
|
|
|
(if (null head-end)
|
|
|
|
(setq head-end (point)))
|
2008-08-21 01:19:58 +02:00
|
|
|
(magit-wash-diff-markup-hunk head-seq hunk-seq
|
|
|
|
head-beg head-end hunk-beg)
|
2008-08-11 00:28:35 +02:00
|
|
|
(setq hunk-seq (+ hunk-seq 1))
|
2008-08-04 02:52:16 +02:00
|
|
|
(setq hunk-beg (point)))
|
2008-08-19 22:43:34 +02:00
|
|
|
((looking-at "^ ")
|
2008-08-19 23:55:42 +02:00
|
|
|
(magit-put-line-property 'face 'magit-diff-none))
|
2008-08-04 02:26:34 +02:00
|
|
|
((string-match "\\+" prefix)
|
2008-08-19 23:55:42 +02:00
|
|
|
(magit-put-line-property 'face 'magit-diff-add))
|
2008-08-04 02:26:34 +02:00
|
|
|
((string-match "-" prefix)
|
2008-08-19 23:55:42 +02:00
|
|
|
(magit-put-line-property 'face 'magit-diff-del))))
|
2008-08-04 02:26:34 +02:00
|
|
|
(forward-line)
|
|
|
|
(beginning-of-line))
|
2008-08-21 01:19:58 +02:00
|
|
|
(magit-wash-diff-markup-diff head-seq head-beg head-end)
|
|
|
|
(magit-wash-diff-markup-hunk head-seq hunk-seq
|
|
|
|
head-beg head-end hunk-beg)))
|
2008-08-04 02:26:34 +02:00
|
|
|
|
2008-08-07 00:49:35 +02:00
|
|
|
(defun magit-update-status (buf)
|
2008-08-11 00:28:35 +02:00
|
|
|
(with-current-buffer buf
|
|
|
|
(let ((old-line (line-number-at-pos))
|
|
|
|
(old-section (magit-section-at-point))
|
|
|
|
(inhibit-read-only t))
|
2008-08-07 00:49:35 +02:00
|
|
|
(erase-buffer)
|
|
|
|
(let* ((branch (magit-get-current-branch))
|
|
|
|
(remote (and branch (magit-get "branch" branch "remote"))))
|
|
|
|
(if remote
|
|
|
|
(insert (format "Remote: %s %s\n"
|
|
|
|
remote (magit-get "remote" remote "url"))))
|
|
|
|
(insert (format "Local: %s %s\n"
|
2008-08-19 22:43:34 +02:00
|
|
|
(propertize (or branch "(detached)")
|
2008-08-19 23:55:42 +02:00
|
|
|
'face 'magit-branch)
|
2008-08-07 00:49:35 +02:00
|
|
|
(abbreviate-file-name default-directory)))
|
2008-08-11 14:46:17 +02:00
|
|
|
(insert
|
|
|
|
(format "Head: %s\n"
|
|
|
|
(magit-shell
|
|
|
|
"git log --max-count=1 --abbrev-commit --pretty=oneline")))
|
2008-08-07 00:49:35 +02:00
|
|
|
(let ((merge-heads (magit-file-lines ".git/MERGE_HEAD")))
|
|
|
|
(if merge-heads
|
|
|
|
(insert (format "Merging: %s\n"
|
|
|
|
(magit-concat-with-delim
|
|
|
|
", "
|
|
|
|
(mapcar 'magit-name-rev merge-heads))))))
|
2008-08-13 04:28:16 +02:00
|
|
|
(let ((rebase (magit-rebase-info)))
|
|
|
|
(if rebase
|
|
|
|
(insert (apply 'format "Rebasing: %s (%s of %s)\n" rebase))))
|
2008-08-07 00:49:35 +02:00
|
|
|
(insert "\n")
|
2008-08-11 00:28:35 +02:00
|
|
|
(magit-insert-section 'untracked
|
2008-08-21 01:19:58 +02:00
|
|
|
"Untracked files:" 'magit-wash-untracked-files
|
|
|
|
"git" "ls-files" "--others" "--exclude-standard")
|
2008-08-11 00:28:35 +02:00
|
|
|
(magit-insert-section 'unstaged
|
|
|
|
"Unstaged changes:" 'magit-wash-diff
|
|
|
|
"git" "diff")
|
|
|
|
(magit-insert-section 'staged
|
|
|
|
"Staged changes:" 'magit-wash-diff
|
|
|
|
"git" "diff" "--cached")
|
2008-08-16 20:59:30 +02:00
|
|
|
(if remote
|
|
|
|
(magit-insert-section 'unpushed
|
|
|
|
"Unpushed commits:" 'magit-wash-log
|
|
|
|
"git" "log" "--graph" "--pretty=oneline"
|
|
|
|
(format "%s/%s..HEAD" remote branch))))
|
2008-08-13 16:25:32 +02:00
|
|
|
(magit-goto-line old-line)
|
2008-08-30 19:37:44 +02:00
|
|
|
(magit-goto-section old-section)
|
|
|
|
(when (bobp)
|
|
|
|
(magit-goto-section '(unstaged 1 1))))
|
2008-08-19 23:58:34 +02:00
|
|
|
(magit-refresh-marks-in-buffer buf)
|
|
|
|
(magit-highlight-item)))
|
2008-08-07 00:49:35 +02:00
|
|
|
|
2008-08-17 01:27:00 +02:00
|
|
|
(defun magit-find-buffer (submode &optional dir)
|
2008-08-07 00:49:35 +02:00
|
|
|
(let ((topdir (magit-get-top-dir (or dir default-directory))))
|
|
|
|
(dolist (buf (buffer-list))
|
|
|
|
(if (save-excursion
|
|
|
|
(set-buffer buf)
|
|
|
|
(and (equal default-directory topdir)
|
2008-08-17 01:27:00 +02:00
|
|
|
(eq major-mode 'magit-mode)
|
|
|
|
(eq magit-submode submode)))
|
2008-08-07 00:49:35 +02:00
|
|
|
(return buf)))))
|
2008-08-05 18:09:47 +02:00
|
|
|
|
2008-08-17 01:27:00 +02:00
|
|
|
(defun magit-find-status-buffer (&optional dir)
|
|
|
|
(magit-find-buffer 'status dir))
|
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-status (dir)
|
|
|
|
(interactive (list (magit-read-top-dir current-prefix-arg)))
|
2008-08-06 00:53:39 +02:00
|
|
|
(save-some-buffers)
|
2008-08-07 00:49:35 +02:00
|
|
|
(let* ((topdir (magit-get-top-dir dir))
|
|
|
|
(buf (or (magit-find-status-buffer topdir)
|
2008-08-23 23:59:10 +02:00
|
|
|
(switch-to-buffer
|
|
|
|
(generate-new-buffer
|
|
|
|
(concat "*magit: "
|
|
|
|
(file-name-nondirectory
|
|
|
|
(directory-file-name topdir)) "*"))))))
|
2008-08-03 20:33:25 +02:00
|
|
|
(switch-to-buffer buf)
|
2008-08-17 01:27:00 +02:00
|
|
|
(magit-mode-init topdir 'status)
|
2008-08-07 00:49:35 +02:00
|
|
|
(magit-update-status buf)))
|
2008-08-01 13:37:54 +02:00
|
|
|
|
2008-08-04 01:05:02 +02:00
|
|
|
;;; Staging
|
2008-08-01 15:04:52 +02:00
|
|
|
|
2008-08-21 01:25:57 +02:00
|
|
|
(defun magit-write-hunk-item-patch (item file)
|
2008-08-21 01:19:58 +02:00
|
|
|
(write-region (magit-hunk-item-head-beg item)
|
|
|
|
(magit-hunk-item-head-end item)
|
|
|
|
file)
|
|
|
|
(write-region (magit-item-beginning item)
|
|
|
|
(magit-item-ending item)
|
|
|
|
file
|
|
|
|
t))
|
2008-08-04 03:10:48 +02:00
|
|
|
|
2008-08-21 01:19:58 +02:00
|
|
|
(defun magit-hunk-item-is-conflict-p (item)
|
2008-08-05 18:09:47 +02:00
|
|
|
(save-excursion
|
2008-08-21 01:19:58 +02:00
|
|
|
(goto-char (magit-hunk-item-head-beg item))
|
2008-08-15 20:33:17 +02:00
|
|
|
(looking-at "^diff --cc")))
|
2008-08-05 18:09:47 +02:00
|
|
|
|
2008-08-21 01:19:58 +02:00
|
|
|
(defun magit-diff-item-conflict-file (item)
|
2008-08-05 18:09:47 +02:00
|
|
|
(save-excursion
|
2008-08-21 01:19:58 +02:00
|
|
|
(goto-char (magit-item-beginning item))
|
2008-08-05 18:09:47 +02:00
|
|
|
(if (looking-at "^diff --cc +\\(.*\\)$")
|
|
|
|
(match-string 1)
|
|
|
|
nil)))
|
2008-08-05 23:30:37 +02:00
|
|
|
|
2008-08-21 01:19:58 +02:00
|
|
|
(defun magit-diff-or-hunk-item-file (item)
|
2008-08-05 23:30:37 +02:00
|
|
|
(save-excursion
|
2008-08-21 01:19:58 +02:00
|
|
|
(goto-char (if (eq (magit-item-type item) 'hunk)
|
|
|
|
(magit-hunk-item-head-beg item)
|
|
|
|
(magit-item-beginning item)))
|
2008-08-05 23:30:37 +02:00
|
|
|
(cond ((looking-at "^diff --git a/\\(.*\\) b/\\(.*\\)$")
|
|
|
|
(match-string 2))
|
|
|
|
((looking-at "^diff --cc +\\(.*\\)$")
|
|
|
|
(match-string 1))
|
|
|
|
(t
|
|
|
|
nil))))
|
|
|
|
|
2008-08-21 01:19:58 +02:00
|
|
|
(defun magit-hunk-item-target-line (item)
|
2008-08-11 02:22:50 +02:00
|
|
|
(save-excursion
|
|
|
|
(beginning-of-line)
|
|
|
|
(let ((line (line-number-at-pos)))
|
|
|
|
(if (looking-at "-")
|
|
|
|
(error "Can't visit removed lines."))
|
2008-08-21 01:19:58 +02:00
|
|
|
(goto-char (magit-item-beginning item))
|
2008-08-11 02:22:50 +02:00
|
|
|
(if (not (looking-at "@@+ .* \\+\\([0-9]+\\),[0-9]+ @@+"))
|
|
|
|
(error "Hunk header not found."))
|
|
|
|
(let ((target (parse-integer (match-string 1))))
|
|
|
|
(forward-line)
|
|
|
|
(while (< (line-number-at-pos) line)
|
2008-08-21 01:23:08 +02:00
|
|
|
;; XXX - deal with combined diffs
|
2008-08-11 02:22:50 +02:00
|
|
|
(if (not (looking-at "-"))
|
|
|
|
(setq target (+ target 1)))
|
|
|
|
(forward-line))
|
|
|
|
target))))
|
|
|
|
|
2008-08-30 19:54:51 +02:00
|
|
|
(defun magit-apply-hunk-item (item &rest args)
|
|
|
|
(magit-write-hunk-item-patch item ".git/magit-tmp")
|
|
|
|
(apply #'magit-run "git" "apply" (append args (list ".git/magit-tmp"))))
|
|
|
|
|
2008-08-30 22:18:27 +02:00
|
|
|
(defun magit-must-be-unstaged (item)
|
|
|
|
(if (eq (magit-item-context item) 'staged)
|
|
|
|
(error "Already staged"))
|
|
|
|
(if (not (eq (magit-item-context item) 'unstaged))
|
|
|
|
(error "Can't stage this.")))
|
|
|
|
|
|
|
|
(defun magit-must-be-staged (item)
|
|
|
|
(if (eq (magit-item-context item) 'unstaged)
|
|
|
|
(error "Not staged"))
|
|
|
|
(if (not (eq (magit-item-context item) 'staged))
|
|
|
|
(error "Can't unstage this.")))
|
|
|
|
|
2008-08-21 01:19:58 +02:00
|
|
|
(defun magit-stage-item ()
|
|
|
|
"Add the item at point to the staging area."
|
2008-08-01 15:04:52 +02:00
|
|
|
(interactive)
|
2008-08-24 01:31:49 +02:00
|
|
|
(magit-item-case (item info "stage")
|
|
|
|
((untracked-file)
|
|
|
|
(magit-run "git" "add" info))
|
|
|
|
((hunk)
|
2008-08-30 22:18:27 +02:00
|
|
|
(magit-must-be-unstaged item)
|
2008-08-24 01:31:49 +02:00
|
|
|
(if (magit-hunk-item-is-conflict-p item)
|
|
|
|
(error "Can't stage individual resolution hunks. Please stage the whole file."))
|
2008-08-30 19:54:51 +02:00
|
|
|
(magit-apply-hunk-item item "--cached"))
|
2008-08-24 01:31:49 +02:00
|
|
|
((diff)
|
2008-08-30 22:18:27 +02:00
|
|
|
(magit-must-be-unstaged item)
|
2008-08-24 01:31:49 +02:00
|
|
|
(magit-run "git" "add" (magit-diff-or-hunk-item-file item)))))
|
2008-08-01 15:04:52 +02:00
|
|
|
|
2008-08-21 01:19:58 +02:00
|
|
|
(defun magit-unstage-item ()
|
|
|
|
"Remove the item at point from the staging area."
|
2008-08-04 03:13:23 +02:00
|
|
|
(interactive)
|
2008-08-24 01:31:49 +02:00
|
|
|
(magit-item-case (item info "unstage")
|
|
|
|
((hunk)
|
2008-08-30 22:18:27 +02:00
|
|
|
(magit-must-be-staged item)
|
2008-08-30 19:54:51 +02:00
|
|
|
(magit-apply-hunk-item item "--cached" "--reverse"))
|
2008-08-24 01:31:49 +02:00
|
|
|
((diff)
|
2008-08-30 22:18:27 +02:00
|
|
|
(magit-must-be-staged item)
|
2008-08-24 01:31:49 +02:00
|
|
|
(magit-run "git" "reset" "HEAD"
|
|
|
|
(magit-diff-or-hunk-item-file item)))))
|
2008-08-04 03:13:23 +02:00
|
|
|
|
2008-08-06 02:22:22 +02:00
|
|
|
(defun magit-stage-all ()
|
2008-08-04 02:26:34 +02:00
|
|
|
(interactive)
|
2008-08-18 21:07:00 +02:00
|
|
|
(magit-run "git" "add" "-u" "."))
|
2008-08-04 02:26:34 +02:00
|
|
|
|
2008-08-20 23:19:15 +02:00
|
|
|
(defun magit-unstage-all ()
|
|
|
|
(interactive)
|
|
|
|
(magit-run "git" "reset" "HEAD"))
|
|
|
|
|
2008-08-06 00:08:07 +02:00
|
|
|
;;; Branches
|
|
|
|
|
2008-08-16 23:37:50 +02:00
|
|
|
(defun magit-checkout (rev)
|
2008-08-17 00:40:04 +02:00
|
|
|
(interactive (list (magit-read-rev "Switch to" (magit-default-rev))))
|
2008-08-16 23:37:50 +02:00
|
|
|
(if rev
|
|
|
|
(magit-run "git" "checkout" (magit-rev-to-git rev))))
|
2008-08-21 01:19:58 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-read-create-branch-args ()
|
2008-08-16 23:37:50 +02:00
|
|
|
(let* ((cur-branch (magit-get-current-branch))
|
2008-08-06 00:08:07 +02:00
|
|
|
(branch (read-string "Create branch: "))
|
2008-08-17 00:40:04 +02:00
|
|
|
(parent (magit-read-rev "Parent" cur-branch)))
|
2008-08-06 00:08:07 +02:00
|
|
|
(list branch parent)))
|
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-create-branch (branch parent)
|
|
|
|
(interactive (magit-read-create-branch-args))
|
2008-08-06 01:32:27 +02:00
|
|
|
(if (and branch (not (string= branch ""))
|
2008-08-16 23:37:50 +02:00
|
|
|
parent)
|
|
|
|
(magit-run "git" "checkout" "-b"
|
|
|
|
branch
|
|
|
|
(magit-rev-to-git parent))))
|
2008-08-06 00:08:07 +02:00
|
|
|
|
2008-08-06 00:17:34 +02:00
|
|
|
;;; Merging
|
|
|
|
|
2008-08-16 23:37:50 +02:00
|
|
|
(defun magit-manual-merge (rev)
|
2008-08-17 00:40:04 +02:00
|
|
|
(interactive (list (magit-read-rev "Manually merge")))
|
2008-08-16 23:37:50 +02:00
|
|
|
(if rev
|
|
|
|
(magit-run "git" "merge" "--no-ff" "--no-commit"
|
|
|
|
(magit-rev-to-git rev))))
|
2008-08-06 00:17:34 +02:00
|
|
|
|
2008-08-16 23:37:50 +02:00
|
|
|
(defun magit-automatic-merge (rev)
|
2008-08-17 00:40:04 +02:00
|
|
|
(interactive (list (magit-read-rev "Merge")))
|
2008-08-16 23:37:50 +02:00
|
|
|
(if rev
|
2008-08-17 01:54:44 +02:00
|
|
|
(magit-run "git" "merge" (magit-rev-to-git rev))))
|
2008-08-06 00:17:34 +02:00
|
|
|
|
2008-08-13 04:28:16 +02:00
|
|
|
;;; Rebasing
|
|
|
|
|
|
|
|
(defun magit-rebase-info ()
|
|
|
|
(cond ((file-exists-p ".dotest")
|
|
|
|
(list (magit-name-rev (car (magit-file-lines ".dotest/onto")))
|
|
|
|
(car (magit-file-lines ".dotest/next"))
|
|
|
|
(car (magit-file-lines ".dotest/last"))))
|
|
|
|
((file-exists-p ".git/.dotest-merge")
|
|
|
|
(list (car (magit-file-lines ".git/.dotest-merge/onto_name"))
|
|
|
|
(car (magit-file-lines ".git/.dotest-merge/msgnum"))
|
|
|
|
(car (magit-file-lines ".git/.dotest-merge/end"))))
|
|
|
|
(t
|
|
|
|
nil)))
|
|
|
|
|
|
|
|
(defun magit-rebase-step ()
|
|
|
|
(interactive)
|
|
|
|
(let ((info (magit-rebase-info)))
|
|
|
|
(if (not info)
|
2008-08-17 00:40:04 +02:00
|
|
|
(let ((rev (magit-read-rev "Rebase to")))
|
2008-08-16 23:37:50 +02:00
|
|
|
(if rev
|
2008-08-21 01:19:58 +02:00
|
|
|
(magit-run "git" "rebase" (magit-rev-to-git rev))))
|
2008-08-13 04:28:16 +02:00
|
|
|
(let ((cursor-in-echo-area t)
|
|
|
|
(message-log-max nil))
|
|
|
|
(message "Rebase in progress. Abort, Skip, or Continue? ")
|
|
|
|
(let ((reply (read-event)))
|
|
|
|
(case reply
|
|
|
|
((?A ?a)
|
|
|
|
(magit-run "git" "rebase" "--abort"))
|
|
|
|
((?S ?s)
|
|
|
|
(magit-run "git" "rebase" "--skip"))
|
|
|
|
((?C ?c)
|
|
|
|
(magit-run "git" "rebase" "--continue"))))))))
|
|
|
|
|
2008-08-06 13:41:48 +02:00
|
|
|
;;; Resetting
|
|
|
|
|
2008-08-16 23:37:50 +02:00
|
|
|
(defun magit-reset-head (rev)
|
2008-08-20 22:57:51 +02:00
|
|
|
(interactive (list (magit-read-rev "Reset head to"
|
|
|
|
(or (magit-default-rev)
|
|
|
|
"HEAD^"))))
|
2008-08-16 23:37:50 +02:00
|
|
|
(if rev
|
|
|
|
(magit-run "git" "reset" "--soft" (magit-rev-to-git rev))))
|
2008-08-06 13:48:03 +02:00
|
|
|
|
2008-08-16 23:37:50 +02:00
|
|
|
(defun magit-reset-working-tree ()
|
2008-08-16 23:43:49 +02:00
|
|
|
(interactive)
|
2008-08-16 23:37:50 +02:00
|
|
|
(if (yes-or-no-p "Discard all uncommitted changes? ")
|
|
|
|
(magit-run "git" "reset" "--hard")))
|
2008-08-06 13:41:48 +02:00
|
|
|
|
2008-08-20 23:18:04 +02:00
|
|
|
;;; Updating, pull, and push
|
|
|
|
|
|
|
|
(defun magit-remote-update ()
|
|
|
|
(interactive)
|
|
|
|
(magit-run "git" "remote" "update"))
|
2008-08-04 01:05:02 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-pull ()
|
2008-08-05 01:30:32 +02:00
|
|
|
(interactive)
|
2008-08-06 01:41:05 +02:00
|
|
|
(magit-run "git" "pull" "-v"))
|
2008-08-04 01:05:02 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-push ()
|
2008-08-05 01:30:32 +02:00
|
|
|
(interactive)
|
2008-08-06 01:41:05 +02:00
|
|
|
(magit-run "git" "push" "-v"))
|
2008-08-04 01:05:02 +02:00
|
|
|
|
2008-08-16 23:37:50 +02:00
|
|
|
;;; Committing
|
2008-08-01 15:04:52 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defvar magit-log-edit-map nil)
|
2008-08-04 14:35:25 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(when (not magit-log-edit-map)
|
|
|
|
(setq magit-log-edit-map (make-sparse-keymap))
|
|
|
|
(define-key magit-log-edit-map (kbd "C-c C-c") 'magit-log-edit-commit))
|
2008-08-04 14:35:25 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defvar magit-pre-log-edit-window-configuration nil)
|
2008-08-04 14:35:25 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-log-edit-cleanup ()
|
2008-08-05 21:30:10 +02:00
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(flush-lines "^#")
|
|
|
|
(goto-char (point-min))
|
2008-08-13 05:14:53 +02:00
|
|
|
(if (re-search-forward "[ \t\n]*\\'" nil t)
|
|
|
|
(replace-match "\n" nil nil))))
|
2008-08-05 21:30:10 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-log-edit-commit ()
|
2008-08-04 14:35:25 +02:00
|
|
|
(interactive)
|
2008-08-06 01:41:05 +02:00
|
|
|
(magit-log-edit-cleanup)
|
2008-08-04 23:30:16 +02:00
|
|
|
(if (> (buffer-size) 0)
|
2008-08-06 01:41:05 +02:00
|
|
|
(write-region (point-min) (point-max) ".git/magit-log")
|
|
|
|
(write-region "(Empty description)" nil ".git/magit-log"))
|
2008-08-04 23:06:56 +02:00
|
|
|
(erase-buffer)
|
2008-08-18 21:07:00 +02:00
|
|
|
(magit-run "git" "commit" "-F" ".git/magit-log")
|
2008-08-04 14:35:25 +02:00
|
|
|
(bury-buffer)
|
2008-08-06 01:41:05 +02:00
|
|
|
(when magit-pre-log-edit-window-configuration
|
|
|
|
(set-window-configuration magit-pre-log-edit-window-configuration)
|
|
|
|
(setq magit-pre-log-edit-window-configuration nil)))
|
2008-08-04 14:35:25 +02:00
|
|
|
|
2008-08-06 01:41:05 +02:00
|
|
|
(defun magit-log-edit ()
|
2008-08-01 15:04:52 +02:00
|
|
|
(interactive)
|
2008-08-04 14:35:25 +02:00
|
|
|
(let ((dir default-directory)
|
2008-08-29 00:39:01 +02:00
|
|
|
(buf (get-buffer-create "*magit-log-edit*")))
|
2008-08-06 03:18:41 +02:00
|
|
|
(setq magit-pre-log-edit-window-configuration
|
|
|
|
(current-window-configuration))
|
2008-08-04 14:35:25 +02:00
|
|
|
(pop-to-buffer buf)
|
|
|
|
(setq default-directory dir)
|
2008-08-06 01:41:05 +02:00
|
|
|
(use-local-map magit-log-edit-map)
|
2008-08-06 03:18:41 +02:00
|
|
|
(message "Type C-c C-c to commit.")))
|
2008-08-04 01:05:02 +02:00
|
|
|
|
2008-08-11 02:23:54 +02:00
|
|
|
(defun magit-add-log ()
|
|
|
|
(interactive)
|
2008-08-21 01:19:58 +02:00
|
|
|
(let ((item (magit-get-item)))
|
|
|
|
(if (not (and item (eq (magit-item-type item) 'hunk)))
|
|
|
|
(error "No hunk at point."))
|
|
|
|
(let ((fun (save-window-excursion
|
2008-08-11 02:23:54 +02:00
|
|
|
(save-excursion
|
2008-08-21 01:19:58 +02:00
|
|
|
(magit-visit-item)
|
2008-08-11 02:23:54 +02:00
|
|
|
(add-log-current-defun))))
|
2008-08-21 01:19:58 +02:00
|
|
|
(file (magit-diff-or-hunk-item-file item)))
|
|
|
|
(magit-log-edit)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(cond ((not (search-forward-regexp (format "^\\* %s" (regexp-quote file))
|
|
|
|
nil t))
|
|
|
|
;; No entry for file, create it.
|
|
|
|
(goto-char (point-max))
|
|
|
|
(insert (format "\n* %s (%s): " file fun)))
|
|
|
|
(t
|
|
|
|
;; found entry for file, look for fun
|
|
|
|
(let ((limit (or (search-forward-regexp "^\\* " nil t)
|
|
|
|
(point-max))))
|
|
|
|
(cond ((search-forward-regexp (format "(.*\\<%s\\>.*):"
|
|
|
|
(regexp-quote fun))
|
|
|
|
limit t)
|
|
|
|
;; found it, goto end of current entry
|
|
|
|
(if (search-forward-regexp "^(" limit t)
|
|
|
|
(backward-char 2)
|
|
|
|
(goto-char limit)))
|
|
|
|
(t
|
|
|
|
;; not found insert new entry
|
|
|
|
(goto-char limit)
|
|
|
|
(beginning-of-line)
|
|
|
|
(open-line 1)
|
|
|
|
(insert (format "(%s): " fun))))))))))
|
2008-08-11 02:23:54 +02:00
|
|
|
|
2008-08-16 23:37:50 +02:00
|
|
|
;;; Commits
|
2008-08-11 04:10:10 +02:00
|
|
|
|
2008-08-17 00:37:48 +02:00
|
|
|
(defun magit-commit-at-point (&optional nil-ok-p)
|
2008-08-21 01:19:58 +02:00
|
|
|
(let* ((item (magit-get-item))
|
|
|
|
(commit (and item
|
|
|
|
(eq (magit-item-type item) 'commit)
|
|
|
|
(magit-item-info item))))
|
2008-08-17 00:37:48 +02:00
|
|
|
(if nil-ok-p
|
|
|
|
commit
|
|
|
|
(or commit
|
|
|
|
(error "No commit at point.")))))
|
2008-08-11 04:10:10 +02:00
|
|
|
|
2008-08-30 20:15:02 +02:00
|
|
|
(defun magit-append-to-log-edit (str)
|
|
|
|
(save-excursion
|
|
|
|
(set-buffer (get-buffer-create "*magit-log-edit*"))
|
|
|
|
(goto-char (point-max))
|
|
|
|
(insert str "\n")))
|
|
|
|
|
|
|
|
(defun magit-escape-for-shell (str)
|
|
|
|
(concat "'" (replace-regexp-in-string "'" "'\\''" str) "'"))
|
|
|
|
|
|
|
|
(defun magit-format-commit (commit format)
|
|
|
|
(magit-shell "git log --max-count=1 --pretty=format:%s %s"
|
|
|
|
(magit-escape-for-shell format)
|
|
|
|
commit))
|
|
|
|
|
2008-08-24 04:28:38 +02:00
|
|
|
(defun magit-apply-item ()
|
2008-08-11 04:10:10 +02:00
|
|
|
(interactive)
|
2008-08-24 04:28:38 +02:00
|
|
|
(magit-item-case (item info "apply")
|
|
|
|
((commit)
|
2008-08-30 20:15:02 +02:00
|
|
|
(magit-append-to-log-edit
|
|
|
|
(magit-format-commit info "%s%n%n%b%n(Cherrypicked from %H)"))
|
2008-08-30 21:34:40 +02:00
|
|
|
(magit-run-shell "git diff %s^ %s | git apply -" info info))))
|
2008-08-11 04:10:10 +02:00
|
|
|
|
2008-08-30 20:37:01 +02:00
|
|
|
(defun magit-cherry-pick ()
|
|
|
|
(interactive)
|
|
|
|
(magit-item-case (item info "apply")
|
|
|
|
((commit)
|
|
|
|
(magit-run "git" "cherry-pick" info))))
|
|
|
|
|
2008-08-24 04:28:38 +02:00
|
|
|
(defun magit-revert-item ()
|
2008-08-11 17:32:07 +02:00
|
|
|
(interactive)
|
2008-08-24 04:28:38 +02:00
|
|
|
(magit-item-case (item info "revert")
|
|
|
|
((commit)
|
2008-08-30 20:15:02 +02:00
|
|
|
(magit-append-to-log-edit
|
2008-08-30 21:47:43 +02:00
|
|
|
(magit-format-commit info "Reverting \"%s\""))
|
|
|
|
(magit-run-shell "git diff %s^ %s | git apply --reverse -" info info))))
|
2008-08-11 17:32:07 +02:00
|
|
|
|
2008-08-24 02:01:29 +02:00
|
|
|
(defvar magit-currently-shown-commit nil)
|
|
|
|
|
|
|
|
(defun magit-show-commit (commit &optional scroll)
|
2008-08-11 17:32:07 +02:00
|
|
|
(let ((dir default-directory)
|
|
|
|
(commit (magit-commit-at-point))
|
2008-08-11 04:10:10 +02:00
|
|
|
(buf (get-buffer-create "*magit-commit*")))
|
2008-08-24 02:01:29 +02:00
|
|
|
(cond ((equal magit-currently-shown-commit commit)
|
|
|
|
(let ((win (get-buffer-window buf)))
|
|
|
|
(cond ((not win)
|
|
|
|
(display-buffer buf))
|
|
|
|
(scroll
|
|
|
|
(with-selected-window win
|
|
|
|
(funcall scroll))))))
|
|
|
|
(t
|
|
|
|
(setq magit-currently-shown-commit commit)
|
|
|
|
(display-buffer buf)
|
|
|
|
(save-excursion
|
|
|
|
(set-buffer buf)
|
|
|
|
(magit-mode-init dir 'commit)
|
|
|
|
(let ((inhibit-read-only t))
|
|
|
|
(erase-buffer)
|
|
|
|
(magit-insert-section 'commit nil 'magit-wash-diff
|
|
|
|
"git" "log" "--max-count=1" "--cc" "-p"
|
|
|
|
commit)))))))
|
2008-08-11 04:10:10 +02:00
|
|
|
|
|
|
|
(defun magit-wash-log (status)
|
|
|
|
(goto-char (point-min))
|
2008-08-24 04:21:36 +02:00
|
|
|
(let ((seq 0))
|
|
|
|
(while (not (eobp))
|
|
|
|
(when (search-forward-regexp "[0-9a-fA-F]\\{40\\}" (line-end-position) t)
|
|
|
|
(let ((commit (match-string-no-properties 0)))
|
|
|
|
(delete-region (match-beginning 0) (match-end 0))
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
(fixup-whitespace)
|
|
|
|
(magit-markup-item (line-beginning-position)
|
|
|
|
(line-beginning-position 2)
|
|
|
|
'commit commit)
|
|
|
|
(magit-markup-section (line-beginning-position)
|
|
|
|
(line-beginning-position 2)
|
|
|
|
1 seq)
|
|
|
|
(setq seq (+ 1 seq))))
|
|
|
|
(forward-line))))
|
2008-08-11 04:10:10 +02:00
|
|
|
|
2008-08-16 23:37:50 +02:00
|
|
|
(defun magit-log (range)
|
|
|
|
(interactive (list (magit-read-rev-range "Log" (magit-get-current-branch))))
|
|
|
|
(if range
|
|
|
|
(let* ((topdir (magit-get-top-dir default-directory))
|
|
|
|
(args (magit-rev-range-to-git range)))
|
|
|
|
(switch-to-buffer "*magit-log*")
|
2008-08-17 01:27:00 +02:00
|
|
|
(magit-mode-init topdir 'log)
|
2008-08-16 23:37:50 +02:00
|
|
|
(let ((inhibit-read-only t))
|
|
|
|
(save-excursion
|
|
|
|
(erase-buffer)
|
|
|
|
(magit-insert-section 'history
|
|
|
|
(magit-rev-range-describe range "Commits")
|
|
|
|
'magit-wash-log
|
|
|
|
"git" "log" "--graph" "--max-count=10000"
|
|
|
|
"--pretty=oneline" args)))
|
|
|
|
(magit-refresh-marks-in-buffer (current-buffer)))))
|
|
|
|
|
|
|
|
(defun magit-log-head ()
|
2008-08-11 04:16:43 +02:00
|
|
|
(interactive)
|
2008-08-16 23:37:50 +02:00
|
|
|
(magit-log "HEAD"))
|
2008-08-12 01:42:13 +02:00
|
|
|
|
|
|
|
;;; Diffing
|
|
|
|
|
2008-08-16 23:37:50 +02:00
|
|
|
(defun magit-diff (range)
|
|
|
|
(interactive (list (magit-read-rev-range "Diff")))
|
|
|
|
(if range
|
|
|
|
(let* ((dir default-directory)
|
|
|
|
(args (magit-rev-range-to-git range))
|
|
|
|
(buf (get-buffer-create "*magit-diff*")))
|
|
|
|
(display-buffer buf)
|
|
|
|
(save-excursion
|
|
|
|
(set-buffer buf)
|
2008-08-17 01:27:00 +02:00
|
|
|
(magit-mode-init dir 'diff)
|
2008-08-16 23:37:50 +02:00
|
|
|
(let ((inhibit-read-only t))
|
|
|
|
(erase-buffer)
|
|
|
|
(magit-insert-section 'diff
|
|
|
|
(magit-rev-range-describe range "Changes")
|
|
|
|
'magit-wash-diff
|
|
|
|
"git" "diff" args))))))
|
|
|
|
|
2008-08-17 01:35:05 +02:00
|
|
|
(defun magit-diff-working-tree (rev)
|
2008-08-17 00:40:04 +02:00
|
|
|
(interactive (list (magit-read-rev "Diff with")))
|
2008-08-16 23:37:50 +02:00
|
|
|
(if rev
|
2008-08-17 01:35:05 +02:00
|
|
|
(magit-diff rev)))
|
2008-08-12 02:14:54 +02:00
|
|
|
|
2008-08-16 23:37:50 +02:00
|
|
|
(defun magit-diff-with-mark ()
|
|
|
|
(interactive)
|
|
|
|
(magit-diff (cons (magit-marked-object)
|
|
|
|
(magit-commit-at-point))))
|
2008-08-12 01:42:13 +02:00
|
|
|
|
|
|
|
;;; Markers
|
|
|
|
|
|
|
|
(defun magit-marked-object ()
|
|
|
|
(save-excursion
|
|
|
|
(set-buffer (magit-find-status-buffer))
|
|
|
|
magit-marked-object))
|
|
|
|
|
|
|
|
(defun magit-set-marked-object (object)
|
|
|
|
(save-excursion
|
|
|
|
(set-buffer (magit-find-status-buffer))
|
|
|
|
(setq magit-marked-object object)))
|
|
|
|
|
|
|
|
(defun magit-refresh-marks-in-buffer (buf)
|
|
|
|
(let ((marked (magit-marked-object)))
|
|
|
|
(save-excursion
|
|
|
|
(set-buffer buf)
|
|
|
|
(let ((inhibit-read-only t))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (not (eobp))
|
2008-08-21 01:19:58 +02:00
|
|
|
(let ((item (get-text-property (point) 'magit-item))
|
2008-08-12 01:42:13 +02:00
|
|
|
(next-change (or (next-single-property-change (point)
|
2008-08-21 01:19:58 +02:00
|
|
|
'magit-item)
|
2008-08-12 01:42:13 +02:00
|
|
|
(point-max))))
|
2008-08-21 01:19:58 +02:00
|
|
|
(if (and item (eq (magit-item-type item) 'commit))
|
2008-08-12 01:42:13 +02:00
|
|
|
(put-text-property (point) next-change
|
2008-08-21 01:19:58 +02:00
|
|
|
'face (if (equal marked
|
|
|
|
(magit-item-info item))
|
2008-08-12 01:42:13 +02:00
|
|
|
'(:foreground "red")
|
|
|
|
nil)))
|
|
|
|
(goto-char next-change)))))))
|
|
|
|
|
|
|
|
(defun magit-refresh-marks ()
|
|
|
|
(let ((status-buffer (magit-find-status-buffer)))
|
|
|
|
(magit-refresh-marks-in-buffer (current-buffer))
|
|
|
|
(if (not (eq (current-buffer) status-buffer))
|
|
|
|
(magit-refresh-marks-in-buffer status-buffer))))
|
|
|
|
|
2008-08-21 01:19:58 +02:00
|
|
|
(defun magit-mark-item ()
|
2008-08-12 01:42:13 +02:00
|
|
|
(interactive)
|
|
|
|
(magit-set-marked-object (magit-commit-at-point))
|
|
|
|
(magit-refresh-marks))
|
|
|
|
|
2008-08-06 02:22:22 +02:00
|
|
|
;;; Miscellaneous
|
2008-08-04 01:05:02 +02:00
|
|
|
|
2008-08-21 01:19:58 +02:00
|
|
|
(defun magit-ignore-item ()
|
2008-08-04 01:05:02 +02:00
|
|
|
(interactive)
|
2008-08-24 01:31:49 +02:00
|
|
|
(magit-item-case (item info "ignore")
|
|
|
|
((untracked-file)
|
|
|
|
(append-to-file (concat "/" info "\n")
|
|
|
|
nil ".gitignore")
|
|
|
|
(magit-update-status (magit-find-status-buffer)))))
|
2008-08-06 02:22:22 +02:00
|
|
|
|
2008-08-21 01:41:43 +02:00
|
|
|
(defun magit-discard-item ()
|
|
|
|
(interactive)
|
2008-08-24 01:31:49 +02:00
|
|
|
(magit-item-case (item info "discard")
|
|
|
|
((untracked-file)
|
2008-08-30 23:28:58 +02:00
|
|
|
(if (yes-or-no-p (format "Delete %s? " info))
|
2008-08-30 19:54:51 +02:00
|
|
|
(magit-run "rm" info)))
|
|
|
|
((hunk)
|
2008-08-30 23:28:58 +02:00
|
|
|
(case (magit-item-context item)
|
|
|
|
((unstaged)
|
|
|
|
(when (yes-or-no-p "Discard hunk? ")
|
|
|
|
(magit-apply-hunk-item item "--reverse")))
|
|
|
|
((staged)
|
|
|
|
(if (magit-file-uptodate-p (magit-diff-or-hunk-item-file item))
|
|
|
|
(when (yes-or-no-p "Discard hunk? ")
|
|
|
|
(magit-apply-hunk-item item "--reverse" "--index"))
|
|
|
|
(error "Can't discard this hunk. Please unstage it first.")))
|
|
|
|
(t
|
|
|
|
(error "Can't discard this hunk."))))
|
2008-08-30 19:54:51 +02:00
|
|
|
((diff)
|
|
|
|
(let ((file (magit-diff-or-hunk-item-file item)))
|
2008-08-30 23:28:58 +02:00
|
|
|
(if (yes-or-no-p (format "Discard changes to %s? " file))
|
2008-08-30 19:54:51 +02:00
|
|
|
(magit-run "git" "checkout" "--" file))))))
|
2008-08-21 01:41:43 +02:00
|
|
|
|
2008-08-21 01:19:58 +02:00
|
|
|
(defun magit-visit-item ()
|
2008-08-06 02:22:22 +02:00
|
|
|
(interactive)
|
2008-08-24 02:01:29 +02:00
|
|
|
(magit-item-case (item info "visit")
|
2008-08-24 01:31:49 +02:00
|
|
|
((untracked-file)
|
|
|
|
(find-file info))
|
|
|
|
((diff hunk)
|
|
|
|
(let ((file (magit-diff-or-hunk-item-file item))
|
|
|
|
(line (if (eq (magit-item-type item) 'hunk)
|
|
|
|
(magit-hunk-item-target-line item)
|
|
|
|
nil)))
|
|
|
|
(find-file file)
|
|
|
|
(if line
|
|
|
|
(goto-line line))))
|
|
|
|
((commit)
|
2008-08-24 02:33:24 +02:00
|
|
|
(magit-show-commit info)
|
2008-08-24 02:01:29 +02:00
|
|
|
(pop-to-buffer "*magit-commit*"))))
|
|
|
|
|
|
|
|
(defun magit-show-item-or-scroll-up ()
|
|
|
|
(interactive)
|
|
|
|
(magit-item-case (item info)
|
|
|
|
((commit)
|
|
|
|
(magit-show-commit info #'scroll-up))))
|
|
|
|
|
|
|
|
(defun magit-show-item-or-scroll-down ()
|
|
|
|
(interactive)
|
|
|
|
(magit-item-case (item info)
|
|
|
|
((commit)
|
|
|
|
(magit-show-commit info #'scroll-down))))
|
2008-08-06 02:22:22 +02:00
|
|
|
|
2008-08-21 01:19:58 +02:00
|
|
|
(defun magit-describe-item ()
|
2008-08-06 14:48:55 +02:00
|
|
|
(interactive)
|
2008-08-21 01:19:58 +02:00
|
|
|
(let ((item (magit-get-item)))
|
|
|
|
(message "Item: %s %s-%s %S"
|
|
|
|
(magit-item-type item)
|
|
|
|
(magit-item-beginning item)
|
|
|
|
(magit-item-ending item)
|
|
|
|
(magit-item-info item))))
|
2008-08-13 05:14:53 +02:00
|
|
|
|
2008-08-21 01:41:43 +02:00
|
|
|
|
2008-08-13 05:14:53 +02:00
|
|
|
(provide 'magit)
|