Renamed to magit.

This commit is contained in:
Marius Vollmer 2008-08-06 02:41:05 +03:00
parent 3cb3b56759
commit 5baf4ddf71

312
magit.el
View file

@ -1,13 +1,13 @@
;;; mgit -- control git from Emacs. ;;; magit -- control git from Emacs.
;; Copyright (C) 2008 Marius Vollmer ;; Copyright (C) 2008 Marius Vollmer
;; ;;
;; Mgit is free software; you can redistribute it and/or modify it ;; Magit is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by ;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option) ;; the Free Software Foundation; either version 3, or (at your option)
;; any later version. ;; any later version.
;; ;;
;; Mgit is distributed in the hope that it will be useful, but WITHOUT ;; Magit is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
;; License for more details. ;; License for more details.
@ -19,7 +19,7 @@
;;; Introduction ;;; Introduction
;; Invoking the mgit-status function will show a buffer with the ;; Invoking the magit-status function will show a buffer with the
;; current status of the current git repository and its checkout. ;; current status of the current git repository and its checkout.
;; That buffer offers key bindings for manipulating the status in ;; That buffer offers key bindings for manipulating the status in
;; simple ways. ;; simple ways.
@ -37,7 +37,7 @@
;;; Utilities ;;; Utilities
(defun mgit-shell (cmd &rest args) (defun magit-shell (cmd &rest args)
(let ((str (shell-command-to-string (apply 'format cmd args)))) (let ((str (shell-command-to-string (apply 'format cmd args))))
(if (string= str "") (if (string= str "")
nil nil
@ -45,7 +45,7 @@
(substring str 0 (- (length str) 1)) (substring str 0 (- (length str) 1))
str)))) str))))
(defun mgit-string-split (string regexp) (defun magit-string-split (string regexp)
(let ((res nil) (let ((res nil)
(pos 0) (pos 0)
next) next)
@ -54,53 +54,53 @@
(setq pos (match-end 0))) (setq pos (match-end 0)))
(nreverse (cons (substring string pos) res)))) (nreverse (cons (substring string pos) res))))
(defun mgit-shell-lines (cmd &rest args) (defun magit-shell-lines (cmd &rest args)
(let ((str (shell-command-to-string (apply 'format cmd args)))) (let ((str (shell-command-to-string (apply 'format cmd args))))
(if (string= str "") (if (string= str "")
nil nil
(mgit-string-split str "\n")))) (magit-string-split str "\n"))))
(defun mgit-concat-with-delim (delim seqs) (defun magit-concat-with-delim (delim seqs)
(cond ((null seqs) (cond ((null seqs)
nil) nil)
((null (cdr seqs)) ((null (cdr seqs))
(car seqs)) (car seqs))
(t (t
(concat (car seqs) delim (mgit-concat-with-delim delim (cdr seqs)))))) (concat (car seqs) delim (magit-concat-with-delim delim (cdr seqs))))))
(defun mgit-get (&rest keys) (defun magit-get (&rest keys)
(mgit-shell "git-config %s" (mgit-concat-with-delim "." keys))) (magit-shell "git-config %s" (magit-concat-with-delim "." keys)))
(defun mgit-set (val &rest keys) (defun magit-set (val &rest keys)
(if val (if val
(mgit-shell "git-config %s %s" (mgit-concat-with-delim "." keys) val) (magit-shell "git-config %s %s" (magit-concat-with-delim "." keys) val)
(mgit-shell "git-config --unset %s" (mgit-concat-with-delim "." keys)))) (magit-shell "git-config --unset %s" (magit-concat-with-delim "." keys))))
(defun mgit-get-top-dir (cwd) (defun magit-get-top-dir (cwd)
(let* ((cwd (expand-file-name cwd)) (let* ((cwd (expand-file-name cwd))
(mgit-dir (mgit-shell "cd '%s' && git-rev-parse --git-dir 2>/dev/null" (magit-dir (magit-shell "cd '%s' && git-rev-parse --git-dir 2>/dev/null"
cwd))) cwd)))
(if mgit-dir (if magit-dir
(file-name-as-directory (or (file-name-directory mgit-dir) cwd)) (file-name-as-directory (or (file-name-directory magit-dir) cwd))
nil))) nil)))
(defun mgit-get-ref (ref) (defun magit-get-ref (ref)
(mgit-shell "git-symbolic-ref -q %s" ref)) (magit-shell "git-symbolic-ref -q %s" ref))
(defun mgit-get-current-branch () (defun magit-get-current-branch ()
(let* ((head (mgit-get-ref "HEAD")) (let* ((head (magit-get-ref "HEAD"))
(pos (and head (string-match "^refs/heads/" head)))) (pos (and head (string-match "^refs/heads/" head))))
(if pos (if pos
(substring head 11) (substring head 11)
nil))) nil)))
(defun mgit-read-top-dir (prefix) (defun magit-read-top-dir (prefix)
(let ((dir (mgit-get-top-dir default-directory))) (let ((dir (magit-get-top-dir default-directory)))
(if prefix (if prefix
(mgit-get-top-dir (read-directory-name "Git repository: " dir)) (magit-get-top-dir (read-directory-name "Git repository: " dir))
dir))) dir)))
(defun mgit-insert-output (title washer cmd &rest args) (defun magit-insert-output (title washer cmd &rest args)
(if title (if title
(insert (propertize title 'face 'bold) "\n")) (insert (propertize title 'face 'bold) "\n"))
(let* ((beg (point)) (let* ((beg (point))
@ -113,16 +113,16 @@
(goto-char (point-max)) (goto-char (point-max))
(insert "\n"))))) (insert "\n")))))
(defun mgit-put-line-property (prop val) (defun magit-put-line-property (prop val)
(put-text-property (line-beginning-position) (line-end-position) (put-text-property (line-beginning-position) (line-end-position)
prop val)) prop val))
;;; Running asynchronous commands ;;; Running asynchronous commands
(defvar mgit-process nil) (defvar magit-process nil)
(defun mgit-run (cmd &rest args) (defun magit-run (cmd &rest args)
(or (not mgit-process) (or (not magit-process)
(error "Git is already running.")) (error "Git is already running."))
(let ((dir default-directory) (let ((dir default-directory)
(buf (get-buffer-create "*git-process*"))) (buf (get-buffer-create "*git-process*")))
@ -130,12 +130,12 @@
(set-buffer buf) (set-buffer buf)
(setq default-directory dir) (setq default-directory dir)
(erase-buffer) (erase-buffer)
(insert "$ " (mgit-concat-with-delim " " (cons cmd args)) "\n") (insert "$ " (magit-concat-with-delim " " (cons cmd args)) "\n")
(setq mgit-process (apply 'start-process "git" buf cmd args)) (setq magit-process (apply 'start-process "git" buf cmd args))
(set-process-sentinel mgit-process 'mgit-process-sentinel)))) (set-process-sentinel magit-process 'magit-process-sentinel))))
(defun mgit-revert-files () (defun magit-revert-files ()
(let ((files (mgit-shell-lines "git ls-files"))) (let ((files (magit-shell-lines "git ls-files")))
(dolist (file files) (dolist (file files)
(let ((buffer (find-buffer-visiting file))) (let ((buffer (find-buffer-visiting file)))
(when (and buffer (when (and buffer
@ -145,74 +145,74 @@
(ignore-errors (ignore-errors
(revert-buffer t t t)))))))) (revert-buffer t t t))))))))
(defun mgit-process-sentinel (process event) (defun magit-process-sentinel (process event)
(cond ((string= event "finished\n") (cond ((string= event "finished\n")
(message "Git finished.") (message "Git finished.")
(setq mgit-process nil)) (setq magit-process nil))
((string= event "killed\n") ((string= event "killed\n")
(message "Git was killed.") (message "Git was killed.")
(setq mgit-process nil)) (setq magit-process nil))
((string-match "exited abnormally" event) ((string-match "exited abnormally" event)
(message "Git failed.") (message "Git failed.")
(setq mgit-process nil)) (setq magit-process nil))
(t (t
(message "Git is weird."))) (message "Git is weird.")))
(mgit-revert-files) (magit-revert-files)
(mgit-update-status)) (magit-update-status))
(defun mgit-display-process () (defun magit-display-process ()
(interactive) (interactive)
(display-buffer "*git-process*")) (display-buffer "*git-process*"))
;;; Keymap ;;; Keymap
(defvar mgit-keymap nil) (defvar magit-keymap nil)
(when (not mgit-keymap) (when (not magit-keymap)
(setq mgit-keymap (make-keymap)) (setq magit-keymap (make-keymap))
(suppress-keymap mgit-keymap) (suppress-keymap magit-keymap)
(define-key mgit-keymap (kbd "g") 'mgit-status) (define-key magit-keymap (kbd "g") 'magit-status)
(define-key mgit-keymap (kbd "A") 'mgit-stage-all) (define-key magit-keymap (kbd "A") 'magit-stage-all)
(define-key mgit-keymap (kbd "a") 'mgit-stage-thing-at-point) (define-key magit-keymap (kbd "a") 'magit-stage-thing-at-point)
(define-key mgit-keymap (kbd "u") 'mgit-unstage-thing-at-point) (define-key magit-keymap (kbd "u") 'magit-unstage-thing-at-point)
(define-key mgit-keymap (kbd "i") 'mgit-ignore-thing-at-point) (define-key magit-keymap (kbd "i") 'magit-ignore-thing-at-point)
(define-key mgit-keymap (kbd "RET") 'mgit-visit-thing-at-point) (define-key magit-keymap (kbd "RET") 'magit-visit-thing-at-point)
(define-key mgit-keymap (kbd "b") 'mgit-switch-branch) (define-key magit-keymap (kbd "b") 'magit-switch-branch)
(define-key mgit-keymap (kbd "B") 'mgit-create-branch) (define-key magit-keymap (kbd "B") 'magit-create-branch)
(define-key mgit-keymap (kbd "m") 'mgit-manual-merge) (define-key magit-keymap (kbd "m") 'magit-manual-merge)
(define-key mgit-keymap (kbd "M") 'mgit-automatic-merge) (define-key magit-keymap (kbd "M") 'magit-automatic-merge)
(define-key mgit-keymap (kbd "U") 'mgit-pull) (define-key magit-keymap (kbd "U") 'magit-pull)
(define-key mgit-keymap (kbd "P") 'mgit-push) (define-key magit-keymap (kbd "P") 'magit-push)
(define-key mgit-keymap (kbd "c") 'mgit-log-edit) (define-key magit-keymap (kbd "c") 'magit-log-edit)
(define-key mgit-keymap (kbd "p") 'mgit-display-process)) (define-key magit-keymap (kbd "p") 'magit-display-process))
;;; Status ;;; Status
(defun mgit-wash-other-files (status) (defun magit-wash-other-files (status)
(goto-char (point-min)) (goto-char (point-min))
(while (not (eobp)) (while (not (eobp))
(let ((filename (buffer-substring (point) (line-end-position)))) (let ((filename (buffer-substring (point) (line-end-position))))
(insert " ") (insert " ")
(mgit-put-line-property 'face '(:foreground "red")) (magit-put-line-property 'face '(:foreground "red"))
(mgit-put-line-property 'mgit-info (list 'other-file filename))) (magit-put-line-property 'magit-info (list 'other-file filename)))
(forward-line) (forward-line)
(beginning-of-line))) (beginning-of-line)))
(defun mgit-wash-diff-propertize-diff (head-beg head-end) (defun magit-wash-diff-propertize-diff (head-beg head-end)
(let ((head-end (or head-end (point)))) (let ((head-end (or head-end (point))))
(when head-beg (when head-beg
(put-text-property head-beg head-end (put-text-property head-beg head-end
'mgit-info (list 'diff 'magit-info (list 'diff
head-beg (point)))))) head-beg (point))))))
(defun mgit-wash-diff-propertize-hunk (head-beg head-end hunk-beg) (defun magit-wash-diff-propertize-hunk (head-beg head-end hunk-beg)
(when hunk-beg (when hunk-beg
(put-text-property hunk-beg (point) (put-text-property hunk-beg (point)
'mgit-info (list 'hunk 'magit-info (list 'hunk
head-beg head-end head-beg head-end
hunk-beg (point))))) hunk-beg (point)))))
(defun mgit-wash-diff (status) (defun magit-wash-diff (status)
(goto-char (point-min)) (goto-char (point-min))
(let ((n-files 1) (let ((n-files 1)
(head-beg nil) (head-beg nil)
@ -222,82 +222,82 @@
(let ((prefix (buffer-substring-no-properties (let ((prefix (buffer-substring-no-properties
(point) (+ (point) n-files)))) (point) (+ (point) n-files))))
(cond ((looking-at "^diff") (cond ((looking-at "^diff")
(mgit-wash-diff-propertize-diff head-beg head-end) (magit-wash-diff-propertize-diff head-beg head-end)
(setq head-beg (point)) (setq head-beg (point))
(setq head-end nil)) (setq head-end nil))
((looking-at "^@+") ((looking-at "^@+")
(setq n-files (- (length (match-string 0)) 1)) (setq n-files (- (length (match-string 0)) 1))
(if (null head-end) (if (null head-end)
(setq head-end (point))) (setq head-end (point)))
(mgit-wash-diff-propertize-hunk head-beg head-end hunk-beg) (magit-wash-diff-propertize-hunk head-beg head-end hunk-beg)
(setq hunk-beg (point))) (setq hunk-beg (point)))
((string-match "\\+" prefix) ((string-match "\\+" prefix)
(mgit-put-line-property 'face '(:foreground "blue1"))) (magit-put-line-property 'face '(:foreground "blue1")))
((string-match "-" prefix) ((string-match "-" prefix)
(mgit-put-line-property 'face '(:foreground "red"))))) (magit-put-line-property 'face '(:foreground "red")))))
(forward-line) (forward-line)
(beginning-of-line)) (beginning-of-line))
(mgit-wash-diff-propertize-diff head-beg head-end) (magit-wash-diff-propertize-diff head-beg head-end)
(mgit-wash-diff-propertize-hunk head-beg head-end hunk-beg))) (magit-wash-diff-propertize-hunk head-beg head-end hunk-beg)))
(defun mgit-update-status () (defun magit-update-status ()
(let ((buf (get-buffer "*git-status*"))) (let ((buf (get-buffer "*git-status*")))
(save-excursion (save-excursion
(set-buffer buf) (set-buffer buf)
(setq buffer-read-only t) (setq buffer-read-only t)
(use-local-map mgit-keymap) (use-local-map magit-keymap)
(let ((inhibit-read-only t)) (let ((inhibit-read-only t))
(erase-buffer) (erase-buffer)
(let* ((branch (mgit-get-current-branch)) (let* ((branch (magit-get-current-branch))
(remote (and branch (mgit-get "branch" branch "remote")))) (remote (and branch (magit-get "branch" branch "remote"))))
(if remote (if remote
(insert (format "Remote: %s %s\n" (insert (format "Remote: %s %s\n"
remote (mgit-get "remote" remote "url")))) remote (magit-get "remote" remote "url"))))
(insert (format "Local: %s %s\n" (insert (format "Local: %s %s\n"
(propertize (or branch "(detached)") 'face 'bold) (propertize (or branch "(detached)") 'face 'bold)
(abbreviate-file-name default-directory))) (abbreviate-file-name default-directory)))
(insert "\n") (insert "\n")
(mgit-insert-output "Untracked files:" 'mgit-wash-other-files (magit-insert-output "Untracked files:" 'magit-wash-other-files
"git" "ls-files" "--others" "--exclude-standard") "git" "ls-files" "--others" "--exclude-standard")
(mgit-insert-output "Unstaged changes:" 'mgit-wash-diff (magit-insert-output "Unstaged changes:" 'magit-wash-diff
"git" "diff") "git" "diff")
(mgit-insert-output "Staged changes:" 'mgit-wash-diff (magit-insert-output "Staged changes:" 'magit-wash-diff
"git" "diff" "--cached") "git" "diff" "--cached")
(if remote (if remote
(mgit-insert-output "Unpushed changes:" 'mgit-wash-diff (magit-insert-output "Unpushed changes:" 'magit-wash-diff
"git" "diff" "--stat" "git" "diff" "--stat"
(format "%s/%s..HEAD" remote branch)))))))) (format "%s/%s..HEAD" remote branch))))))))
(defun mgit-status (dir) (defun magit-status (dir)
(interactive (list (mgit-read-top-dir current-prefix-arg))) (interactive (list (magit-read-top-dir current-prefix-arg)))
(save-some-buffers) (save-some-buffers)
(let ((buf (get-buffer-create "*git-status*"))) (let ((buf (get-buffer-create "*git-status*")))
(switch-to-buffer buf) (switch-to-buffer buf)
(setq default-directory dir) (setq default-directory dir)
(mgit-update-status))) (magit-update-status)))
;;; Staging ;;; Staging
(defun mgit-write-diff-patch (info file) (defun magit-write-diff-patch (info file)
(write-region (elt info 1) (elt info 2) file)) (write-region (elt info 1) (elt info 2) file))
(defun mgit-write-hunk-patch (info file) (defun magit-write-hunk-patch (info file)
(write-region (elt info 1) (elt info 2) file) (write-region (elt info 1) (elt info 2) file)
(write-region (elt info 3) (elt info 4) file t)) (write-region (elt info 3) (elt info 4) file t))
(defun mgit-hunk-is-conflict-p (info) (defun magit-hunk-is-conflict-p (info)
(save-excursion (save-excursion
(goto-char (elt info 1)) (goto-char (elt info 1))
(looking-at-p "^diff --cc"))) (looking-at-p "^diff --cc")))
(defun mgit-diff-conflict-file (info) (defun magit-diff-conflict-file (info)
(save-excursion (save-excursion
(goto-char (elt info 1)) (goto-char (elt info 1))
(if (looking-at "^diff --cc +\\(.*\\)$") (if (looking-at "^diff --cc +\\(.*\\)$")
(match-string 1) (match-string 1)
nil))) nil)))
(defun mgit-diff-info-file (info) (defun magit-diff-info-file (info)
(save-excursion (save-excursion
(goto-char (elt info 1)) (goto-char (elt info 1))
(cond ((looking-at "^diff --git a/\\(.*\\) b/\\(.*\\)$") (cond ((looking-at "^diff --git a/\\(.*\\) b/\\(.*\\)$")
@ -307,7 +307,7 @@
(t (t
nil)))) nil))))
(defun mgit-diff-info-position (info) (defun magit-diff-info-position (info)
(save-excursion (save-excursion
(cond ((eq (car info) 'hunk) (cond ((eq (car info) 'hunk)
(goto-char (elt info 3)) (goto-char (elt info 3))
@ -316,144 +316,144 @@
nil)) nil))
(t nil)))) (t nil))))
(defun mgit-stage-thing-at-point () (defun magit-stage-thing-at-point ()
(interactive) (interactive)
(let ((info (get-char-property (point) 'mgit-info))) (let ((info (get-char-property (point) 'magit-info)))
(if info (if info
(case (car info) (case (car info)
((other-file) ((other-file)
(mgit-run "git" "add" (cadr info))) (magit-run "git" "add" (cadr info)))
((hunk) ((hunk)
(if (mgit-hunk-is-conflict-p info) (if (magit-hunk-is-conflict-p info)
(error (error
"Can't stage individual resolution hunks. Please stage the whole file.")) "Can't stage individual resolution hunks. Please stage the whole file."))
(mgit-write-hunk-patch info ".git/mgit-tmp") (magit-write-hunk-patch info ".git/magit-tmp")
(mgit-run "git" "apply" "--cached" ".git/mgit-tmp")) (magit-run "git" "apply" "--cached" ".git/magit-tmp"))
((diff) ((diff)
(mgit-run "git" "add" (mgit-diff-info-file info))))))) (magit-run "git" "add" (magit-diff-info-file info)))))))
(defun mgit-unstage-thing-at-point () (defun magit-unstage-thing-at-point ()
(interactive) (interactive)
(let ((info (get-char-property (point) 'mgit-info))) (let ((info (get-char-property (point) 'magit-info)))
(if info (if info
(case (car info) (case (car info)
((hunk) ((hunk)
(mgit-write-hunk-patch info ".git/mgit-tmp") (magit-write-hunk-patch info ".git/magit-tmp")
(mgit-run "git" "apply" "--cached" "--reverse" ".git/mgit-tmp")) (magit-run "git" "apply" "--cached" "--reverse" ".git/magit-tmp"))
((diff) ((diff)
(mgit-run "git" "reset" "HEAD" (mgit-diff-info-file info))))))) (magit-run "git" "reset" "HEAD" (magit-diff-info-file info)))))))
(defun mgit-ignore-thing-at-point () (defun magit-ignore-thing-at-point ()
(interactive) (interactive)
(let ((info (get-char-property (point) 'mgit-info))) (let ((info (get-char-property (point) 'magit-info)))
(if info (if info
(case (car info) (case (car info)
((other-file) ((other-file)
(append-to-file (concat (cadr info) "\n") nil ".gitignore") (append-to-file (concat (cadr info) "\n") nil ".gitignore")
(mgit-update-status)))))) (magit-update-status))))))
(defun mgit-visit-thing-at-point () (defun magit-visit-thing-at-point ()
(interactive) (interactive)
(let ((info (get-char-property (point) 'mgit-info))) (let ((info (get-char-property (point) 'magit-info)))
(if info (if info
(case (car info) (case (car info)
((other-file) ((other-file)
(find-file (cadr info))) (find-file (cadr info)))
((diff hunk) ((diff hunk)
(let ((file (mgit-diff-info-file info)) (let ((file (magit-diff-info-file info))
(position (mgit-diff-info-position info))) (position (magit-diff-info-position info)))
(find-file file) (find-file file)
(if position (if position
(goto-line position)))))))) (goto-line position))))))))
;;; Branches ;;; Branches
(defun mgit-list-branches () (defun magit-list-branches ()
(mgit-shell-lines "git branch -a | cut -c3-")) (magit-shell-lines "git branch -a | cut -c3-"))
(defun mgit-read-other-branch (prompt) (defun magit-read-other-branch (prompt)
(completing-read prompt (delete (mgit-get-current-branch) (completing-read prompt (delete (magit-get-current-branch)
(mgit-list-branches)) (magit-list-branches))
nil t)) nil t))
(defun mgit-switch-branch (branch) (defun magit-switch-branch (branch)
(interactive (list (mgit-read-other-branch "Switch to branch: "))) (interactive (list (magit-read-other-branch "Switch to branch: ")))
(if (and branch (not (string= branch ""))) (if (and branch (not (string= branch "")))
(mgit-run "git" "checkout" branch))) (magit-run "git" "checkout" branch)))
(defun mgit-read-create-branch-args () (defun magit-read-create-branch-args ()
(let* ((branches (mgit-list-branches)) (let* ((branches (magit-list-branches))
(cur-branch (mgit-get-current-branch)) (cur-branch (magit-get-current-branch))
(branch (read-string "Create branch: ")) (branch (read-string "Create branch: "))
(parent (completing-read "Parent: " branches nil t cur-branch))) (parent (completing-read "Parent: " branches nil t cur-branch)))
(list branch parent))) (list branch parent)))
(defun mgit-create-branch (branch parent) (defun magit-create-branch (branch parent)
(interactive (mgit-read-create-branch-args)) (interactive (magit-read-create-branch-args))
(if (and branch (not (string= branch "")) (if (and branch (not (string= branch ""))
parent (not (string= parent ""))) parent (not (string= parent "")))
(mgit-run "git" "checkout" "-b" branch parent))) (magit-run "git" "checkout" "-b" branch parent)))
;;; Merging ;;; Merging
(defun mgit-manual-merge (branch) (defun magit-manual-merge (branch)
(interactive (list (mgit-read-other-branch "Manually merge from branch: "))) (interactive (list (magit-read-other-branch "Manually merge from branch: ")))
(mgit-run "git" "merge" "--no-ff" "--no-commit" branch)) (magit-run "git" "merge" "--no-ff" "--no-commit" branch))
(defun mgit-automatic-merge (branch) (defun magit-automatic-merge (branch)
(interactive (list (mgit-read-other-branch "Merge from branch: "))) (interactive (list (magit-read-other-branch "Merge from branch: ")))
(mgit-run "git" "merge" branch)) (magit-run "git" "merge" branch))
;;; Push and pull ;;; Push and pull
(defun mgit-pull () (defun magit-pull ()
(interactive) (interactive)
(mgit-run "git" "pull" "-v")) (magit-run "git" "pull" "-v"))
(defun mgit-push () (defun magit-push ()
(interactive) (interactive)
(mgit-run "git" "push" "-v")) (magit-run "git" "push" "-v"))
;;; Commit ;;; Commit
(defvar mgit-log-edit-map nil) (defvar magit-log-edit-map nil)
(when (not mgit-log-edit-map) (when (not magit-log-edit-map)
(setq mgit-log-edit-map (make-sparse-keymap)) (setq magit-log-edit-map (make-sparse-keymap))
(define-key mgit-log-edit-map (kbd "C-c C-c") 'mgit-log-edit-commit)) (define-key magit-log-edit-map (kbd "C-c C-c") 'magit-log-edit-commit))
(defvar mgit-pre-log-edit-window-configuration nil) (defvar magit-pre-log-edit-window-configuration nil)
(defun mgit-log-edit-cleanup () (defun magit-log-edit-cleanup ()
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
(flush-lines "^#") (flush-lines "^#")
(goto-char (point-min)) (goto-char (point-min))
(replace-regexp "[ \t\n]*\\'" "\n"))) (replace-regexp "[ \t\n]*\\'" "\n")))
(defun mgit-log-edit-commit () (defun magit-log-edit-commit ()
(interactive) (interactive)
(mgit-log-edit-cleanup) (magit-log-edit-cleanup)
(if (> (buffer-size) 0) (if (> (buffer-size) 0)
(write-region (point-min) (point-max) ".git/mgit-log") (write-region (point-min) (point-max) ".git/magit-log")
(write-region "(Empty description)" nil ".git/mgit-log")) (write-region "(Empty description)" nil ".git/magit-log"))
(erase-buffer) (erase-buffer)
(mgit-run "git-commit" "-F" ".git/mgit-log") (magit-run "git-commit" "-F" ".git/magit-log")
(bury-buffer) (bury-buffer)
(when mgit-pre-log-edit-window-configuration (when magit-pre-log-edit-window-configuration
(set-window-configuration mgit-pre-log-edit-window-configuration) (set-window-configuration magit-pre-log-edit-window-configuration)
(setq mgit-pre-log-edit-window-configuration nil))) (setq magit-pre-log-edit-window-configuration nil)))
(defun mgit-log-edit () (defun magit-log-edit ()
(interactive) (interactive)
(let ((dir default-directory) (let ((dir default-directory)
(buf (get-buffer-create "*git-log-edit*"))) (buf (get-buffer-create "*git-log-edit*")))
(setq mgit-pre-log-edit-window-configuration (current-window-configuration)) (setq magit-pre-log-edit-window-configuration (current-window-configuration))
(pop-to-buffer buf) (pop-to-buffer buf)
(setq default-directory dir) (setq default-directory dir)
(use-local-map mgit-log-edit-map) (use-local-map magit-log-edit-map)
(save-excursion (save-excursion
(mgit-log-edit-cleanup) (magit-log-edit-cleanup)
(if (and (= (buffer-size) 0) (if (and (= (buffer-size) 0)
(file-exists-p ".git/MERGE_MSG")) (file-exists-p ".git/MERGE_MSG"))
(insert-file-contents ".git/MERGE_MSG"))) (insert-file-contents ".git/MERGE_MSG")))
@ -461,6 +461,6 @@
;;; Misc ;;; Misc
(defun mgit-stage-all () (defun magit-stage-all ()
(interactive) (interactive)
(mgit-run "git-add" "-u" ".")) (magit-run "git-add" "-u" "."))