unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* git push/pull [was: support for bzr shelve/unshelve in vc-dir]
@ 2009-12-05  8:09 Fabian Ezequiel Gallina
  2009-12-05  9:07 ` Andreas Schwab
  2009-12-05 16:15 ` git push/pull Stefan Monnier
  0 siblings, 2 replies; 10+ messages in thread
From: Fabian Ezequiel Gallina @ 2009-12-05  8:09 UTC (permalink / raw)
  To: Emacs-Devel devel

I love vc, the thing is I always wanted the hability to do git
push/pull from vc directly. So today I decided to implement it.

Below is the code, I sure there is a lot of room for improvement since
I consider an Emacs LISP newbie myself, but I guess is a good starting
point for a better implementation.

As you might deduce from the code, when calling vc-git-push and
vc-git-pull the user will be prompted for a repository and a refspec,
both prompts feature sane default values (I hope you will agree on
that) and nice minibuffer-completion.


(defvar vc-git-push-pull-perform 'pull
  "The git command `vc-git--do-push-pull' should execute")

(defun vc-git--do-push-pull (&optional repository refspec)
  "Calls git push/pull with REPOSITORY and REFSPEC as parameters.

The decision of using push or pull is beign made depending the
value of `vc-git-push-pull-perform'."
  (interactive
   (let ((default-refspec (vc-git-working-revision buffer-file-name))
         (default-repo)
         (available-repos)
         (available-refspecs)
         (current-repo)
         (current-refspec))
     (setq available-repos
           (let ((table (list ".")))
             (with-temp-buffer
               (vc-git-command t nil nil "for-each-ref" "--format=%(refname)")
               (goto-char (point-min))
               (while (re-search-forward "^refs/remotes/\\([^/]+\\).*$" nil t)
                 (push (match-string 1) table)))
             table))
     (setq default-repo (nth 0 available-repos))
     (setq current-repo
           (completing-read (format "Repository (default %s): " default-repo)
                            available-repos nil 'confirm nil nil default-repo))
     (setq available-refspecs
           (let ((table (list "HEAD"))
                 (ref-regexp))
             (with-temp-buffer
               (vc-git-command t nil nil "for-each-ref" "--format=%(refname)")
               (if (equal current-repo ".")
                   (setq ref-regexp
                         "^refs/\\(remotes\\|heads\\|tags\\)/\\([^\n]*\\)$")
                 (setq ref-regexp (concat "^refs/\\(remotes\\)/"
                                          (regexp-quote current-repo)
                                          "/\\([^\n]+\\).*$")))
               (goto-char (point-min))
               (while (re-search-forward
                       ref-regexp
                       nil t)
                 (push (match-string 2) table)))
             table))
     (setq current-refspec
           (completing-read (format "Branch (default %s): " default-refspec)
                            available-refspecs nil 'confirm nil nil
                            default-refspec))
     (list current-repo current-refspec)))
  (let ((buffer (current-buffer))
        (command-buffer-name "*vc-push-pull*"))
    (vc-git-command
     command-buffer-name 0 nil
     (prin1-to-string vc-git-push-pull-perform) repository refspec)
    (set-buffer command-buffer-name)
    (message (buffer-string))
    (set-buffer buffer)))

(defun vc-git-push (&optional repository refspec)
  "Update remote refs along with associated objects."
  (interactive)
  (setq vc-git-push-pull-perform 'push)
  (call-interactively 'vc-git--do-push-pull))

(defun vc-git-pull (&optional repository refspec)
  "Fetch from and merge with another repository or a local branch."
  (interactive)
  (setq vc-git-push-pull-perform 'pull)
  (call-interactively 'vc-git--do-push-pull))


Now, if this code is good enough. Can it be applied to vc-git.el? If
not can somebody provide a better alternative?

Also it will be really nice to define a menu/keybinding for these two
operations.



Best Regards,
-- 
Fabián E. Gallina
http://www.from-the-cloud.com




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-12-09 17:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-05  8:09 git push/pull [was: support for bzr shelve/unshelve in vc-dir] Fabian Ezequiel Gallina
2009-12-05  9:07 ` Andreas Schwab
2009-12-05 16:15 ` git push/pull Stefan Monnier
2009-12-06  3:12   ` Fabian Ezequiel Gallina
2009-12-06 19:21   ` Fabian Ezequiel Gallina
2009-12-06 20:33     ` Andreas Schwab
2009-12-06 21:13       ` Fabian Ezequiel Gallina
2009-12-06 22:45         ` Andreas Schwab
2009-12-08  4:50     ` Stefan Monnier
2009-12-09 17:19       ` Fabian Ezequiel Gallina

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).