Conflicts:
	magit.el
This commit is contained in:
Aaron Culich 2010-10-07 11:15:06 -07:00
commit a662446c67
3 changed files with 101 additions and 33 deletions

View file

@ -1,4 +1,5 @@
VERSION=0.8.2 VERSION=0.8.2
EMACS=emacs
PREFIX=/usr/local PREFIX=/usr/local
ELS=magit.el magit-svn.el magit-topgit.el magit-key-mode.el ELS=magit.el magit-svn.el magit-topgit.el magit-key-mode.el
ELCS=$(ELS:.el=.elc) ELCS=$(ELS:.el=.elc)
@ -6,9 +7,11 @@ DIST_FILES=$(ELS) Makefile magit.texi README.md magit.spec.in magit-pkg.el.in 50
.PHONY=install .PHONY=install
BATCH=$(EMACS) -batch -q -no-site-file -eval \
"(setq load-path (cons (expand-file-name \".\") load-path))"
%.elc: %.el %.elc: %.el
emacs --batch --eval "(add-to-list 'load-path \"$(CURDIR)\")" \ $(BATCH) --eval '(byte-compile-file "$<")'
--eval '(byte-compile-file "$<")'
all: $(ELCS) magit.info magit.spec magit-pkg.el all: $(ELCS) magit.info magit.spec magit-pkg.el

View file

@ -34,7 +34,7 @@
("-al" "All" "--all")) ("-al" "All" "--all"))
(arguments (arguments
("=r" "Relative" "--relative=" read-directory-name) ("=r" "Relative" "--relative=" read-directory-name)
("=c" "Committer" "--committer" read-from-minibuffer) ("=c" "Committer" "--committer=" read-from-minibuffer)
("=>" "Since" "--since=" read-from-minibuffer) ("=>" "Since" "--since=" read-from-minibuffer)
("=<" "Before" "--before=" read-from-minibuffer) ("=<" "Before" "--before=" read-from-minibuffer)
("=s" "Pickaxe search" "-S" read-from-minibuffer) ("=s" "Pickaxe search" "-S" read-from-minibuffer)
@ -49,14 +49,15 @@
(fetching (fetching
(man-page "git-fetch") (man-page "git-fetch")
(actions (actions
("f" "Fetch" magit-fetch)) ("f" "Current" magit-fetch-current)
(switches ("a" "All" magit-remote-update)
("-a" "All" "--all"))) ("o" "Other" magit-fetch)))
(pushing (pushing
(man-page "git-push") (man-page "git-push")
(actions (actions
("p" "Push" magit-push)) ("p" "Push" magit-push)
("t" "Push tags" magit-push-tags))
(switches (switches
("-f" "Force" "--force") ("-f" "Force" "--force")
("-d" "Dry run" "-n"))) ("-d" "Dry run" "-n")))

112
magit.el
View file

@ -183,6 +183,14 @@ t mean pty, it enable magit to prompt for passphrase when needed."
:group 'magit :group 'magit
:type 'boolean) :type 'boolean)
(defcustom magit-completing-read-function 'magit-builtin-completing-read
"Function to be called when requesting input from the user."
:group 'magit
:type '(radio (function-item magit-iswitchb-completing-read)
(function-item magit-builtin-completing-read)
(function :tag "Other")))
(defface magit-header (defface magit-header
'((t)) '((t))
"Face for generic header lines. "Face for generic header lines.
@ -327,9 +335,6 @@ Many Magit faces inherit from this one by default."
(defvar magit-custom-options '() (defvar magit-custom-options '()
"List of custom options to pass git. Do not customise this.") "List of custom options to pass git. Do not customise this.")
(defvar magit-completing-read 'completing-read
"Function to be called when requesting input from the user.")
(defvar magit-read-rev-history nil (defvar magit-read-rev-history nil
"The history of inputs to `magit-read-rev'.") "The history of inputs to `magit-read-rev'.")
@ -519,6 +524,31 @@ Many Magit faces inherit from this one by default."
(make-variable-buffer-local 'magit-submode) (make-variable-buffer-local 'magit-submode)
(put 'magit-submode 'permanent-local t) (put 'magit-submode 'permanent-local t)
(defun magit-iswitchb-completing-read (prompt choices &optional predicate require-match
initial-input hist def)
"iswitchb-based completing-read almost-replacement."
(require 'iswitchb)
(let ((iswitchb-make-buflist-hook
(lambda ()
(setq iswitchb-temp-buflist (if (consp (first choices))
(mapcar #'car choices)
choices)))))
(iswitchb-read-buffer prompt (or initial-input def) require-match)))
(defun magit-builtin-completing-read (prompt choices &optional predicate require-match
initial-input hist def)
"Magit wrapper for standard completing-read function."
(completing-read (if (and def (> (length prompt) 2)
(string-equal ": " (substring prompt -2)))
(format "%s (default %s): " (substring prompt 0 -2) def)
prompt)
choices predicate require-match initial-input hist def))
(defun magit-completing-read (prompt choices &optional predicate require-match
initial-input hist def)
(funcall magit-completing-read-function prompt choices predicate require-match
initial-input hist def))
(defun magit-use-region-p () (defun magit-use-region-p ()
(if (fboundp 'use-region-p) (if (fboundp 'use-region-p)
(use-region-p) (use-region-p)
@ -686,8 +716,8 @@ Otherwise, return nil."
(defun magit-read-top-dir (rawp) (defun magit-read-top-dir (rawp)
(if (and (not rawp) magit-repo-dirs) (if (and (not rawp) magit-repo-dirs)
(let* ((repos (magit-list-repos magit-repo-dirs)) (let* ((repos (magit-list-repos magit-repo-dirs))
(reply (funcall magit-completing-read "Git repository: " (reply (magit-completing-read "Git repository: "
(magit-list-repos magit-repo-dirs)))) (magit-list-repos magit-repo-dirs))))
(file-name-as-directory (file-name-as-directory
(cdr (assoc reply repos)))) (cdr (assoc reply repos))))
(file-name-as-directory (file-name-as-directory
@ -790,12 +820,14 @@ working directory state (or HEAD in a log buffer). If it's a
pair (START . END), then the range is START..END.") pair (START . END), then the range is START..END.")
(make-variable-buffer-local 'magit-current-range) (make-variable-buffer-local 'magit-current-range)
(defun magit-list-interesting-refs () (defun magit-list-interesting-refs (&optional uninteresting)
(let ((refs ())) (let ((refs ()))
(dolist (line (magit-git-lines "show-ref")) (dolist (line (magit-git-lines "show-ref"))
(if (string-match "[^ ]+ +\\(.*\\)" line) (if (string-match "[^ ]+ +\\(.*\\)" line)
(let ((ref (match-string 1 line))) (let ((ref (match-string 1 line)))
(cond ((string-match "refs/heads/\\(.*\\)" ref) (cond ((loop for i in uninteresting
thereis (string-match i ref)))
((string-match "refs/heads/\\(.*\\)" ref)
(let ((branch (match-string 1 ref))) (let ((branch (match-string 1 ref)))
(push (cons branch branch) refs))) (push (cons branch branch) refs)))
((string-match "refs/tags/\\(.*\\)" ref) ((string-match "refs/tags/\\(.*\\)" ref)
@ -815,15 +847,18 @@ pair (START . END), then the range is START..END.")
(match-string 2 ref))) (match-string 2 ref)))
ref) ref)
refs)))))) refs))))))
refs)) (nreverse refs)))
(defun magit-read-rev (prompt &optional def) (defvar magit-uninteresting-refs '("refs/remotes/\\([^/]+\\)/HEAD$"))
(let* ((prompt (if def
(format "%s (default %s): " prompt def) ;; TODO: fix this so that def can (must?) be git rev instead of, say, "master (origin)"
(format "%s: " prompt))) ;; which involves a particular display strategy and shouldn't be visible to callers
(interesting-refs (magit-list-interesting-refs)) ;; of magit-read-rev
(reply (funcall magit-completing-read prompt interesting-refs (defun magit-read-rev (prompt &optional def uninteresting)
nil nil nil 'magit-read-rev-history def)) (let* ((interesting-refs (magit-list-interesting-refs
(or uninteresting magit-uninteresting-refs)))
(reply (magit-completing-read (concat prompt ": ") interesting-refs
nil nil nil 'magit-read-rev-history def))
(rev (or (cdr (assoc reply interesting-refs)) reply))) (rev (or (cdr (assoc reply interesting-refs)) reply)))
(if (string= rev "") (if (string= rev "")
nil nil
@ -885,14 +920,11 @@ pair (START . END), then the range is START..END.")
"Read the name of a remote. "Read the name of a remote.
PROMPT is used as the prompt, and defaults to \"Remote\". PROMPT is used as the prompt, and defaults to \"Remote\".
DEF is the default value, and defaults to the value of `magit-get-current-branch'." DEF is the default value, and defaults to the value of `magit-get-current-branch'."
(let* ((prompt (or prompt "Remote")) (let* ((prompt (or prompt "Remote: "))
(def (or def (magit-get-current-remote))) (def (or def (magit-get-current-remote)))
(prompt (if def
(format "%s (default %s): " prompt def)
(format "%s: " prompt)))
(remotes (magit-git-lines "remote")) (remotes (magit-git-lines "remote"))
(reply (funcall magit-completing-read prompt remotes (reply (magit-completing-read prompt remotes
nil nil nil nil def))) nil nil nil nil def)))
(if (string= reply "") nil reply))) (if (string= reply "") nil reply)))
;;; Sections ;;; Sections
@ -2809,7 +2841,16 @@ rev... maybe."
Fails if working tree or staging area contain uncommitted changes. Fails if working tree or staging area contain uncommitted changes.
If REVISION is a remote branch, offer to create a local tracking branch. If REVISION is a remote branch, offer to create a local tracking branch.
\('git checkout [-b] REVISION')." \('git checkout [-b] REVISION')."
(interactive (list (magit-read-rev "Switch to" (magit-default-rev)))) (interactive
(list (let ((current-branch (magit-get-current-branch))
(default (magit-default-rev)))
(magit-read-rev "Switch to"
(unless (string= current-branch default)
default)
(if current-branch
(cons (concat "refs/heads/" current-branch)
magit-uninteresting-refs)
magit-uninteresting-refs)))))
(if revision (if revision
(when (not (magit-maybe-create-local-tracking-branch revision)) (when (not (magit-maybe-create-local-tracking-branch revision))
(magit-save-some-buffers) (magit-save-some-buffers)
@ -2897,7 +2938,20 @@ if any."
(interactive) (interactive)
(let ((info (magit-rebase-info))) (let ((info (magit-rebase-info)))
(if (not info) (if (not info)
(let ((rev (magit-read-rev "Rebase to" (magit-guess-branch)))) (let* ((current-branch (magit-get-current-branch))
(remote (when current-branch
(magit-get "branch" current-branch "remote")))
(remote-branch (when remote
(magit-get "branch" current-branch "merge")))
(rev (magit-read-rev "Rebase to"
(when (and remote-branch
(string-match "refs/heads/\\(.*\\)" remote-branch))
(concat (match-string 1 remote-branch)
" (" remote ")"))
(if current-branch
(cons (concat "refs/heads/" current-branch)
magit-uninteresting-refs)
magit-uninteresting-refs))))
(if rev (if rev
(magit-run-git "rebase" (magit-rev-to-git rev)))) (magit-run-git "rebase" (magit-rev-to-git rev))))
(let ((cursor-in-echo-area t) (let ((cursor-in-echo-area t)
@ -3080,6 +3134,11 @@ Uncomitted changes in both working tree and staging area are lost.
(interactive) (interactive)
(magit-run-git-async "fetch" (magit-read-remote))) (magit-run-git-async "fetch" (magit-read-remote)))
(magit-define-command fetch-current ()
"Run fetch."
(interactive)
(magit-run-git-async "fetch"))
(magit-define-command remote-update () (magit-define-command remote-update ()
"Update all remotes." "Update all remotes."
(interactive) (interactive)
@ -3125,6 +3184,11 @@ typing and automatically refreshes the status buffer."
args) args)
nil nil nil t)))) nil nil nil t))))
(magit-define-command push-tags ()
"Push tags."
(interactive)
(magit-run-git-async "push" "--tags"))
(magit-define-command push () (magit-define-command push ()
(interactive) (interactive)
(let* ((branch (or (magit-get-current-branch) (let* ((branch (or (magit-get-current-branch)
@ -3132,7 +3196,7 @@ typing and automatically refreshes the status buffer."
(branch-remote (magit-get-remote branch)) (branch-remote (magit-get-remote branch))
(push-remote (if (or current-prefix-arg (push-remote (if (or current-prefix-arg
(not branch-remote)) (not branch-remote))
(magit-read-remote (format "Push %s to" branch) (magit-read-remote (format "Push %s to: " branch)
branch-remote) branch-remote)
branch-remote)) branch-remote))
(ref-branch (magit-get "branch" branch "merge"))) (ref-branch (magit-get "branch" branch "merge")))