summaryrefslogtreecommitdiff
path: root/lisp/vc/vc-git.el
diff options
context:
space:
mode:
authorChong Yidong <cyd@stupidchicken.com>2011-01-28 22:12:32 -0500
committerChong Yidong <cyd@stupidchicken.com>2011-01-28 22:12:32 -0500
commit659114fdba7d5ea14541cdc713c7f9745eb93c46 (patch)
tree32cbb5f428dc239902df39d7869377b85e2338fb /lisp/vc/vc-git.el
parentbc68bd3998b317499fb5df713470f78fbdf3a78d (diff)
downloademacs-659114fdba7d5ea14541cdc713c7f9745eb93c46.tar.gz
Rudimentary support for vc-pull and vc-merge in Git and Mercurial.
* lisp/vc/vc.el (vc-pull): Make vc-update an alias for this, instead of the other way around. * lisp/vc/vc-git.el (vc-git-branches, vc-git-pull) (vc-git-merge-branch): New functions. (vc-git-history): New var. * lisp/vc/vc-hg.el (vc-hg-history): New var. (vc-hg-pull): Perform default pull if called via Lisp by vc-pull. (vc-hg-merge-branch): New function.
Diffstat (limited to 'lisp/vc/vc-git.el')
-rw-r--r--lisp/vc/vc-git.el51
1 files changed, 51 insertions, 0 deletions
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index c3ffa1fcf46..592fc77e2e3 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -122,6 +122,9 @@ If nil, use the value of `vc-diff-switches'. If t, use no switches."
(defvar vc-git-commits-coding-system 'utf-8
"Default coding system for git commits.")
+;; History of Git commands.
+(defvar vc-git-history nil)
+
;;; BACKEND PROPERTIES
(defun vc-git-revision-granularity () 'repository)
@@ -526,6 +529,21 @@ or an empty string if none."
'help-echo stash-help-echo
'face 'font-lock-variable-name-face))))))
+(defun vc-git-branches ()
+ "Return the existing branches, as a list of strings.
+The car of the list is the current branch."
+ (with-temp-buffer
+ (call-process "git" nil t nil "branch")
+ (goto-char (point-min))
+ (let (current-branch branches)
+ (while (not (eobp))
+ (when (looking-at "^\\([ *]\\) \\(.+\\)$")
+ (if (string-equal (match-string 1) "*")
+ (setq current-branch (match-string 2))
+ (push (match-string 2) branches)))
+ (forward-line 1))
+ (cons current-branch (nreverse branches)))))
+
;;; STATE-CHANGING FUNCTIONS
(defun vc-git-create-repo ()
@@ -587,6 +605,39 @@ or an empty string if none."
(vc-git-command nil 0 file "reset" "-q" "--")
(vc-git-command nil nil file "checkout" "-q" "--")))
+(defun vc-git-pull (prompt)
+ "Pull changes into the current Git branch.
+Normally, this runs \"git pull\".If there is no default
+location from which to pull or update, or if PROMPT is non-nil,
+prompt for the Git command to run."
+ (let* ((root (vc-git-root default-directory))
+ (buffer (format "*vc-git : %s*" (expand-file-name root)))
+ (command "pull")
+ (git-program "git")
+ args)
+ ;; If necessary, prompt for the exact command.
+ (when prompt
+ (setq args (split-string
+ (read-shell-command "Run Git (like this): "
+ "git pull"
+ 'vc-git-history)
+ " " t))
+ (setq git-program (car args)
+ command (cadr args)
+ args (cddr args)))
+ (apply 'vc-do-async-command buffer root git-program command args)))
+
+(defun vc-git-merge-branch ()
+ "Merge changes into the current Git branch.
+This prompts for a branch to merge from."
+ (let* ((root (vc-git-root default-directory))
+ (buffer (format "*vc-git : %s*" (expand-file-name root)))
+ (branches (cdr (vc-git-branches)))
+ (merge-source
+ (completing-read "Merge from branch: " branches nil t)))
+ (apply 'vc-do-async-command buffer root "git" "merge"
+ (list merge-source))))
+
;;; HISTORY FUNCTIONS
(defun vc-git-print-log (files buffer &optional shortlog start-revision limit)