From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Fabian Ezequiel Gallina Newsgroups: gmane.emacs.devel Subject: git push/pull [was: support for bzr shelve/unshelve in vc-dir] Date: Sat, 5 Dec 2009 05:09:39 -0300 Message-ID: <9de1a5ef0912050009i59707986gb177505e04975e1b@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1260000601 16595 80.91.229.12 (5 Dec 2009 08:10:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 5 Dec 2009 08:10:01 +0000 (UTC) To: Emacs-Devel devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 05 09:09:54 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NGpiD-0001Ix-EA for ged-emacs-devel@m.gmane.org; Sat, 05 Dec 2009 09:09:53 +0100 Original-Received: from localhost ([127.0.0.1]:53985 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NGpiD-00055f-51 for ged-emacs-devel@m.gmane.org; Sat, 05 Dec 2009 03:09:53 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NGpi7-00055X-Gc for emacs-devel@gnu.org; Sat, 05 Dec 2009 03:09:47 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NGpi2-000550-5X for emacs-devel@gnu.org; Sat, 05 Dec 2009 03:09:46 -0500 Original-Received: from [199.232.76.173] (port=37075 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NGpi1-00054x-Vv for emacs-devel@gnu.org; Sat, 05 Dec 2009 03:09:42 -0500 Original-Received: from mail-ew0-f211.google.com ([209.85.219.211]:46991) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NGpi1-0001RC-Lu for emacs-devel@gnu.org; Sat, 05 Dec 2009 03:09:41 -0500 Original-Received: by ewy3 with SMTP id 3so179478ewy.33 for ; Sat, 05 Dec 2009 00:09:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=wXimQht/Zc+cmHhFbHzX62PZLuV9Argu6dIAdENUkzM=; b=i5iqX8DbSZXJfnX3EGYpg3Mhiz3VyzE72V/US64CEeXCrqcaKo+kJnj9G025XoGTSn SflcjxVuJNSiaKHZYg3YTHbpmRElkLtcrGuprXNZHSTUBPYV0shMK1W42hrvsbGwn5a3 pHDTmYnMtrWnMFtBNXRxsSzsfNBohJm8hkdBw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=Rs3wgPL1ieDN2SuIqTZpY80FmlQK6Mp+rOmQq84ZiQhLw0eTLqhCpbL1UgO5SauVIg 3ks7h5a0G49Xdrwteo5jqR2RnrHtiJ2f72SoK7Lskh4muDPjy4hjsYylD1lPzEmgg5E7 2IL7ZOs4jRmBGcYpythAp37DNuRQbfK75+pZU= Original-Received: by 10.216.93.1 with SMTP id k1mr1583419wef.151.1260000579630; Sat, 05 Dec 2009 00:09:39 -0800 (PST) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:118294 Archived-At: 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=3D%(refna= me)") (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-rep= o) available-repos nil 'confirm nil nil default-re= po)) (setq available-refspecs (let ((table (list "HEAD")) (ref-regexp)) (with-temp-buffer (vc-git-command t nil nil "for-each-ref" "--format=3D%(refna= me)") (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, --=20 Fabi=E1n E. Gallina http://www.from-the-cloud.com