git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git.el: Add new user functions for push, pull, fetch.
@ 2011-03-22 13:30 jari.aalto
  2011-03-22 14:36 ` [PATCH v2] contrib/emacs/git.el: Add " jari.aalto
  0 siblings, 1 reply; 6+ messages in thread
From: jari.aalto @ 2011-03-22 13:30 UTC (permalink / raw)
  To: git; +Cc: Jari Aalto

From: Jari Aalto <jari.aalto@cante.net>


Signed-off-by: Jari Aalto <jari.aalto@cante.net>
---
 contrib/emacs/git.el |   75 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 74 insertions(+), 1 deletions(-)

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 214930a..20a3b2c 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -1,6 +1,7 @@
 ;;; git.el --- A user interface for git
 
 ;; Copyright (C) 2005, 2006, 2007, 2008, 2009 Alexandre Julliard <julliard@winehq.org>
+;; Copyright (C) 2010 Jari Aalto <jari.aalto@cante.net>
 
 ;; Version: 1.0
 
@@ -33,11 +34,14 @@
 ;;
 ;; To start: `M-x git-status'
 ;;
+;; RUDIMENTARY
+;; - fetch/pull. Be sure to start gpg-agent, ssh-agent prior emacs
+;;   to access ssh Git remotes.
+;;
 ;; TODO
 ;;  - diff against other branch
 ;;  - renaming files from the status buffer
 ;;  - creating tags
-;;  - fetch/pull
 ;;  - revlist browser
 ;;  - git-show-branch browser
 ;;
@@ -1520,6 +1524,7 @@ amended version of it."
 
 (unless git-status-mode-map
   (let ((map (make-keymap))
+        (remote-map (make-sparse-keymap))
         (commit-map (make-sparse-keymap))
         (diff-map (make-sparse-keymap))
         (toggle-map (make-sparse-keymap)))
@@ -1547,6 +1552,7 @@ amended version of it."
     (define-key map "P"   'git-prev-unmerged-file)
     (define-key map "q"   'git-status-quit)
     (define-key map "r"   'git-remove-file)
+    (define-key map "R"   remote-map)
     (define-key map "t"    toggle-map)
     (define-key map "T"   'git-toggle-all-marks)
     (define-key map "u"   'git-unmark-file)
@@ -1555,6 +1561,13 @@ amended version of it."
     (define-key map "x"   'git-remove-handled)
     (define-key map "\C-?" 'git-unmark-file-up)
     (define-key map "\M-\C-?" 'git-unmark-all)
+    ; remotes
+    (define-key remote-map "\C-a" 'git-push)
+    (define-key remote-map "R" 'git-pull)  ; retrieve "RR"
+    (define-key remote-map "r" 'git-pull)  ; retrieve "Rr" (synonym)
+    (define-key remote-map "p" 'git-push)
+    (define-key remote-map "f" 'git-fetch)
+    (define-key remote-map "\C-a" 'git-fetch)
     ; the commit submap
     (define-key commit-map "\C-a" 'git-amend-commit)
     (define-key commit-map "\C-b" 'git-branch)
@@ -1607,6 +1620,10 @@ amended version of it."
       ["Interactive Diff File" git-diff-file-idiff t]
       ["Log" git-log-file t]
       "--------"
+      ["Push" git-push t]
+      ["Pull" git-pull t]
+      ["Fetch" git-fetch t]
+      "--------"
       ["Mark" git-mark-file t]
       ["Mark All" git-mark-all t]
       ["Unmark" git-unmark-file t]
@@ -1689,6 +1706,62 @@ Meant to be used in `after-save-hook'."
             (git-call-process nil "add" "--refresh" "--" filename)
             (git-update-status-files (list filename))))))))
 
+(defun git-ask-remote (message)
+  "Return remote."
+  (let ((ret
+	 (completing-read
+	  "Push to remote: "
+	  '(("origin" 1))		;FIXME read all remotes
+	  (not 'predicate)
+	  (not 'match)
+	  "origin")))
+    (if (not (string-match "[^ \t]" ret))
+	"origin"
+      ret)))
+
+(defun git-push (&optional remote)
+  "Pull to REMOTE. Use \\[current-prefix-arg] to interactively set REMOTE."
+  (interactive
+   (list (or (and current-prefix-arg
+		  (git-ask-remote "Push to remote: "))
+	     "origin")))
+  ;; FIXME: could colled some status data for display
+  (git-call-process-display-error "push" remote)
+  (git-update-status-files)
+  (message "Pushed to remote: %s" remote))
+
+(defun git-fetch (&optional remote)
+  "Fetch from REMOTE. Use \\[current-prefix-arg] to interactively set REMOTE."
+  (interactive
+   (list (or (and current-prefix-arg
+		  (git-ask-remote "Fetch from remote: "))
+	     "origin")))
+  ;; FIXME: could colled some status data for display
+  (git-call-process-display-error "fetch" remote)
+  (git-update-status-files)
+  (message "Fetched from remote: %s" remote))
+
+(defun git-pull (&optional remote)
+  "Pull from REMOTE. Use \\[current-prefix-arg] to interactively set REMOTE."
+  (interactive
+   (list (or (and current-prefix-arg
+		  (git-ask-remote "Pull from remote: "))
+	     "origin")))
+  (let ((not-clean
+	 (ewoc-collect git-status (lambda (info &optional state)
+				    (setq state (git-fileinfo->state info))
+				    (or (eq state 'modified)
+					(eq state 'added)
+					(eq state 'deleted)
+					(eq state 'unmerged))))))
+    (if not-clean
+	(error "Error: Can't pull while in unclean state (commit all first)."))
+    (unless git-status (error "Not in git-status buffer."))
+    ;; FIXME: could colled some status data for display
+    (git-call-process-display-error "pull" remote)
+    (git-update-status-files)
+    (message "Pushed to remote: %s" remote)))
+
 (defun git-help ()
   "Display help for Git mode."
   (interactive)
-- 
1.7.2.3

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

* [PATCH v2] contrib/emacs/git.el: Add user functions for push, pull, fetch
  2011-03-22 13:30 [PATCH] git.el: Add new user functions for push, pull, fetch jari.aalto
@ 2011-03-22 14:36 ` jari.aalto
  2011-04-03 16:13   ` Jari Aalto
  0 siblings, 1 reply; 6+ messages in thread
From: jari.aalto @ 2011-03-22 14:36 UTC (permalink / raw)
  To: git; +Cc: Jari Aalto

From: Jari Aalto <jari.aalto@cante.net>


Signed-off-by: Jari Aalto <jari.aalto@cante.net>
---
 contrib/emacs/git.el |   75 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 74 insertions(+), 1 deletions(-)

  ** This fixes the pull message. The only change is last line:
  ** (message "Pulled from remote: %s" remote)))

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 214930a..1999f0c 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -1,6 +1,7 @@
 ;;; git.el --- A user interface for git
 
 ;; Copyright (C) 2005, 2006, 2007, 2008, 2009 Alexandre Julliard <julliard@winehq.org>
+;; Copyright (C) 2010 Jari Aalto <jari.aalto@cante.net>
 
 ;; Version: 1.0
 
@@ -33,11 +34,14 @@
 ;;
 ;; To start: `M-x git-status'
 ;;
+;; RUDIMENTARY
+;; - fetch/pull. Be sure to start gpg-agent, ssh-agent prior emacs
+;;   to access ssh Git remotes.
+;;
 ;; TODO
 ;;  - diff against other branch
 ;;  - renaming files from the status buffer
 ;;  - creating tags
-;;  - fetch/pull
 ;;  - revlist browser
 ;;  - git-show-branch browser
 ;;
@@ -1520,6 +1524,7 @@ amended version of it."
 
 (unless git-status-mode-map
   (let ((map (make-keymap))
+        (remote-map (make-sparse-keymap))
         (commit-map (make-sparse-keymap))
         (diff-map (make-sparse-keymap))
         (toggle-map (make-sparse-keymap)))
@@ -1547,6 +1552,7 @@ amended version of it."
     (define-key map "P"   'git-prev-unmerged-file)
     (define-key map "q"   'git-status-quit)
     (define-key map "r"   'git-remove-file)
+    (define-key map "R"   remote-map)
     (define-key map "t"    toggle-map)
     (define-key map "T"   'git-toggle-all-marks)
     (define-key map "u"   'git-unmark-file)
@@ -1555,6 +1561,13 @@ amended version of it."
     (define-key map "x"   'git-remove-handled)
     (define-key map "\C-?" 'git-unmark-file-up)
     (define-key map "\M-\C-?" 'git-unmark-all)
+    ; remotes
+    (define-key remote-map "\C-a" 'git-push)
+    (define-key remote-map "R" 'git-pull)  ; retrieve "RR"
+    (define-key remote-map "r" 'git-pull)  ; retrieve "Rr" (synonym)
+    (define-key remote-map "p" 'git-push)
+    (define-key remote-map "f" 'git-fetch)
+    (define-key remote-map "\C-a" 'git-fetch)
     ; the commit submap
     (define-key commit-map "\C-a" 'git-amend-commit)
     (define-key commit-map "\C-b" 'git-branch)
@@ -1607,6 +1620,10 @@ amended version of it."
       ["Interactive Diff File" git-diff-file-idiff t]
       ["Log" git-log-file t]
       "--------"
+      ["Push" git-push t]
+      ["Pull" git-pull t]
+      ["Fetch" git-fetch t]
+      "--------"
       ["Mark" git-mark-file t]
       ["Mark All" git-mark-all t]
       ["Unmark" git-unmark-file t]
@@ -1689,6 +1706,62 @@ Meant to be used in `after-save-hook'."
             (git-call-process nil "add" "--refresh" "--" filename)
             (git-update-status-files (list filename))))))))
 
+(defun git-ask-remote (message)
+  "Return remote."
+  (let ((ret
+	 (completing-read
+	  "Push to remote: "
+	  '(("origin" 1))		;FIXME read all remotes
+	  (not 'predicate)
+	  (not 'match)
+	  "origin")))
+    (if (not (string-match "[^ \t]" ret))
+	"origin"
+      ret)))
+
+(defun git-push (&optional remote)
+  "Pull to REMOTE. Use \\[current-prefix-arg] to interactively set REMOTE."
+  (interactive
+   (list (or (and current-prefix-arg
+		  (git-ask-remote "Push to remote: "))
+	     "origin")))
+  ;; FIXME: could colled some status data for display
+  (git-call-process-display-error "push" remote)
+  (git-update-status-files)
+  (message "Pushed to remote: %s" remote))
+
+(defun git-fetch (&optional remote)
+  "Fetch from REMOTE. Use \\[current-prefix-arg] to interactively set REMOTE."
+  (interactive
+   (list (or (and current-prefix-arg
+		  (git-ask-remote "Fetch from remote: "))
+	     "origin")))
+  ;; FIXME: could colled some status data for display
+  (git-call-process-display-error "fetch" remote)
+  (git-update-status-files)
+  (message "Fetched from remote: %s" remote))
+
+(defun git-pull (&optional remote)
+  "Pull from REMOTE. Use \\[current-prefix-arg] to interactively set REMOTE."
+  (interactive
+   (list (or (and current-prefix-arg
+		  (git-ask-remote "Pull from remote: "))
+	     "origin")))
+  (let ((not-clean
+	 (ewoc-collect git-status (lambda (info &optional state)
+				    (setq state (git-fileinfo->state info))
+				    (or (eq state 'modified)
+					(eq state 'added)
+					(eq state 'deleted)
+					(eq state 'unmerged))))))
+    (if not-clean
+	(error "Error: Can't pull while in unclean state (commit all first)."))
+    (unless git-status (error "Not in git-status buffer."))
+    ;; FIXME: could colled some status data for display
+    (git-call-process-display-error "pull" remote)
+    (git-update-status-files)
+    (message "Pulled from remote: %s" remote)))
+
 (defun git-help ()
   "Display help for Git mode."
   (interactive)
-- 
1.7.2.3

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

* Re: [PATCH v2] contrib/emacs/git.el: Add user functions for push, pull, fetch
  2011-03-22 14:36 ` [PATCH v2] contrib/emacs/git.el: Add " jari.aalto
@ 2011-04-03 16:13   ` Jari Aalto
  2011-04-03 17:27     ` Alexandre Julliard
  0 siblings, 1 reply; 6+ messages in thread
From: Jari Aalto @ 2011-04-03 16:13 UTC (permalink / raw)
  To: git; +Cc: julliard

From: Jari Aalto <jari.aalto@cante.net>

Signed-off-by: Jari Aalto <jari.aalto@cante.net>
---
 contrib/emacs/git.el |   75 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 74 insertions(+), 1 deletions(-)

  [2011-03-22 original message]
  [2011-04-03 This is a ping ...]

  ** This fixes the pull message. The only change is last line:
  ** (message "Pulled from remote: %s" remote)))

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 214930a..1999f0c 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -1,6 +1,7 @@
 ;;; git.el --- A user interface for git
 
 ;; Copyright (C) 2005, 2006, 2007, 2008, 2009 Alexandre Julliard <julliard@winehq.org>
+;; Copyright (C) 2010 Jari Aalto <jari.aalto@cante.net>
 
 ;; Version: 1.0
 
@@ -33,11 +34,14 @@
 ;;
 ;; To start: `M-x git-status'
 ;;
+;; RUDIMENTARY
+;; - fetch/pull. Be sure to start gpg-agent, ssh-agent prior emacs
+;;   to access ssh Git remotes.
+;;
 ;; TODO
 ;;  - diff against other branch
 ;;  - renaming files from the status buffer
 ;;  - creating tags
-;;  - fetch/pull
 ;;  - revlist browser
 ;;  - git-show-branch browser
 ;;
@@ -1520,6 +1524,7 @@ amended version of it."
 
 (unless git-status-mode-map
   (let ((map (make-keymap))
+        (remote-map (make-sparse-keymap))
         (commit-map (make-sparse-keymap))
         (diff-map (make-sparse-keymap))
         (toggle-map (make-sparse-keymap)))
@@ -1547,6 +1552,7 @@ amended version of it."
     (define-key map "P"   'git-prev-unmerged-file)
     (define-key map "q"   'git-status-quit)
     (define-key map "r"   'git-remove-file)
+    (define-key map "R"   remote-map)
     (define-key map "t"    toggle-map)
     (define-key map "T"   'git-toggle-all-marks)
     (define-key map "u"   'git-unmark-file)
@@ -1555,6 +1561,13 @@ amended version of it."
     (define-key map "x"   'git-remove-handled)
     (define-key map "\C-?" 'git-unmark-file-up)
     (define-key map "\M-\C-?" 'git-unmark-all)
+    ; remotes
+    (define-key remote-map "\C-a" 'git-push)
+    (define-key remote-map "R" 'git-pull)  ; retrieve "RR"
+    (define-key remote-map "r" 'git-pull)  ; retrieve "Rr" (synonym)
+    (define-key remote-map "p" 'git-push)
+    (define-key remote-map "f" 'git-fetch)
+    (define-key remote-map "\C-a" 'git-fetch)
     ; the commit submap
     (define-key commit-map "\C-a" 'git-amend-commit)
     (define-key commit-map "\C-b" 'git-branch)
@@ -1607,6 +1620,10 @@ amended version of it."
       ["Interactive Diff File" git-diff-file-idiff t]
       ["Log" git-log-file t]
       "--------"
+      ["Push" git-push t]
+      ["Pull" git-pull t]
+      ["Fetch" git-fetch t]
+      "--------"
       ["Mark" git-mark-file t]
       ["Mark All" git-mark-all t]
       ["Unmark" git-unmark-file t]
@@ -1689,6 +1706,62 @@ Meant to be used in `after-save-hook'."
             (git-call-process nil "add" "--refresh" "--" filename)
             (git-update-status-files (list filename))))))))
 
+(defun git-ask-remote (message)
+  "Return remote."
+  (let ((ret
+	 (completing-read
+	  "Push to remote: "
+	  '(("origin" 1))		;FIXME read all remotes
+	  (not 'predicate)
+	  (not 'match)
+	  "origin")))
+    (if (not (string-match "[^ \t]" ret))
+	"origin"
+      ret)))
+
+(defun git-push (&optional remote)
+  "Pull to REMOTE. Use \\[current-prefix-arg] to interactively set REMOTE."
+  (interactive
+   (list (or (and current-prefix-arg
+		  (git-ask-remote "Push to remote: "))
+	     "origin")))
+  ;; FIXME: could colled some status data for display
+  (git-call-process-display-error "push" remote)
+  (git-update-status-files)
+  (message "Pushed to remote: %s" remote))
+
+(defun git-fetch (&optional remote)
+  "Fetch from REMOTE. Use \\[current-prefix-arg] to interactively set REMOTE."
+  (interactive
+   (list (or (and current-prefix-arg
+		  (git-ask-remote "Fetch from remote: "))
+	     "origin")))
+  ;; FIXME: could colled some status data for display
+  (git-call-process-display-error "fetch" remote)
+  (git-update-status-files)
+  (message "Fetched from remote: %s" remote))
+
+(defun git-pull (&optional remote)
+  "Pull from REMOTE. Use \\[current-prefix-arg] to interactively set REMOTE."
+  (interactive
+   (list (or (and current-prefix-arg
+		  (git-ask-remote "Pull from remote: "))
+	     "origin")))
+  (let ((not-clean
+	 (ewoc-collect git-status (lambda (info &optional state)
+				    (setq state (git-fileinfo->state info))
+				    (or (eq state 'modified)
+					(eq state 'added)
+					(eq state 'deleted)
+					(eq state 'unmerged))))))
+    (if not-clean
+	(error "Error: Can't pull while in unclean state (commit all first)."))
+    (unless git-status (error "Not in git-status buffer."))
+    ;; FIXME: could colled some status data for display
+    (git-call-process-display-error "pull" remote)
+    (git-update-status-files)
+    (message "Pulled from remote: %s" remote)))
+
 (defun git-help ()
   "Display help for Git mode."
   (interactive)

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

* Re: [PATCH v2] contrib/emacs/git.el: Add user functions for push, pull, fetch
  2011-04-03 16:13   ` Jari Aalto
@ 2011-04-03 17:27     ` Alexandre Julliard
  2011-04-03 17:48       ` [PATCH v3] " jari.aalto
  0 siblings, 1 reply; 6+ messages in thread
From: Alexandre Julliard @ 2011-04-03 17:27 UTC (permalink / raw)
  To: Jari Aalto; +Cc: git

Jari Aalto <jari.aalto@cante.net> writes:

> @@ -1555,6 +1561,13 @@ amended version of it."
>      (define-key map "x"   'git-remove-handled)
>      (define-key map "\C-?" 'git-unmark-file-up)
>      (define-key map "\M-\C-?" 'git-unmark-all)
> +    ; remotes
> +    (define-key remote-map "\C-a" 'git-push)
> +    (define-key remote-map "R" 'git-pull)  ; retrieve "RR"
> +    (define-key remote-map "r" 'git-pull)  ; retrieve "Rr" (synonym)
> +    (define-key remote-map "p" 'git-push)
> +    (define-key remote-map "f" 'git-fetch)
> +    (define-key remote-map "\C-a" 'git-fetch)

The \C-a things look strange.

> +(defun git-push (&optional remote)
> +  "Pull to REMOTE. Use \\[current-prefix-arg] to interactively set REMOTE."
> +  (interactive
> +   (list (or (and current-prefix-arg
> +		  (git-ask-remote "Push to remote: "))
> +	     "origin")))
> +  ;; FIXME: could colled some status data for display
> +  (git-call-process-display-error "push" remote)
> +  (git-update-status-files)
> +  (message "Pushed to remote: %s" remote))

You shouldn't display a success message if the call failed. Also there's
no need to refresh the status files on push or fetch.

-- 
Alexandre Julliard
julliard@winehq.org

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

* [PATCH v3] contrib/emacs/git.el: Add user functions for push, pull, fetch
  2011-04-03 17:27     ` Alexandre Julliard
@ 2011-04-03 17:48       ` jari.aalto
  2011-04-14 21:07         ` [PATCH v4] " jari.aalto
  0 siblings, 1 reply; 6+ messages in thread
From: jari.aalto @ 2011-04-03 17:48 UTC (permalink / raw)
  To: git; +Cc: Jari Aalto, julliard

From: Jari Aalto <jari.aalto@cante.net>

Signed-off-by: Jari Aalto <jari.aalto@cante.net>
---
 contrib/emacs/git.el |   70 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 69 insertions(+), 1 deletions(-)

  [v2]
  ** This fixes the pull message. The only change is last line:
  ** (message "Pulled from remote: %s" remote)))

  [v3] Fixes commented by <julliard@winehq.org>
  ** Extra C-a keymap binding removed
  ** Check success status before displaying message
  ** no need to refresh the status files on push or fetch

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 214930a..26510d2 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -1,6 +1,7 @@
 ;;; git.el --- A user interface for git
 
 ;; Copyright (C) 2005, 2006, 2007, 2008, 2009 Alexandre Julliard <julliard@winehq.org>
+;; Copyright (C) 2010 Jari Aalto <jari.aalto@cante.net>
 
 ;; Version: 1.0
 
@@ -33,11 +34,14 @@
 ;;
 ;; To start: `M-x git-status'
 ;;
+;; RUDIMENTARY
+;; - fetch/pull. Be sure to start gpg-agent, ssh-agent prior emacs
+;;   to access ssh Git remotes.
+;;
 ;; TODO
 ;;  - diff against other branch
 ;;  - renaming files from the status buffer
 ;;  - creating tags
-;;  - fetch/pull
 ;;  - revlist browser
 ;;  - git-show-branch browser
 ;;
@@ -1520,6 +1524,7 @@ amended version of it."
 
 (unless git-status-mode-map
   (let ((map (make-keymap))
+        (remote-map (make-sparse-keymap))
         (commit-map (make-sparse-keymap))
         (diff-map (make-sparse-keymap))
         (toggle-map (make-sparse-keymap)))
@@ -1547,6 +1552,7 @@ amended version of it."
     (define-key map "P"   'git-prev-unmerged-file)
     (define-key map "q"   'git-status-quit)
     (define-key map "r"   'git-remove-file)
+    (define-key map "R"   remote-map)
     (define-key map "t"    toggle-map)
     (define-key map "T"   'git-toggle-all-marks)
     (define-key map "u"   'git-unmark-file)
@@ -1555,6 +1561,11 @@ amended version of it."
     (define-key map "x"   'git-remove-handled)
     (define-key map "\C-?" 'git-unmark-file-up)
     (define-key map "\M-\C-?" 'git-unmark-all)
+    ; remotes
+    (define-key remote-map "R" 'git-pull)  ; retrieve "RR"
+    (define-key remote-map "r" 'git-pull)  ; retrieve "Rr" (synonym)
+    (define-key remote-map "p" 'git-push)
+    (define-key remote-map "f" 'git-fetch)
     ; the commit submap
     (define-key commit-map "\C-a" 'git-amend-commit)
     (define-key commit-map "\C-b" 'git-branch)
@@ -1607,6 +1618,10 @@ amended version of it."
       ["Interactive Diff File" git-diff-file-idiff t]
       ["Log" git-log-file t]
       "--------"
+      ["Push" git-push t]
+      ["Pull" git-pull t]
+      ["Fetch" git-fetch t]
+      "--------"
       ["Mark" git-mark-file t]
       ["Mark All" git-mark-all t]
       ["Unmark" git-unmark-file t]
@@ -1689,6 +1704,59 @@ Meant to be used in `after-save-hook'."
             (git-call-process nil "add" "--refresh" "--" filename)
             (git-update-status-files (list filename))))))))
 
+(defun git-ask-remote (message)
+  "Return remote."
+  (let ((ret
+	 (completing-read
+	  "Push to remote: "
+	  '(("origin" 1))		;FIXME read all remotes
+	  (not 'predicate)
+	  (not 'match)
+	  "origin")))
+    (if (not (string-match "[^ \t]" ret))
+	"origin"
+      ret)))
+
+(defun git-push (&optional remote)
+  "Pull to REMOTE. Use \\[current-prefix-arg] to interactively set REMOTE."
+  (interactive
+   (list (or (and current-prefix-arg
+		  (git-ask-remote "Push to remote: "))
+	     "origin")))
+  ;; FIXME: could collect some status data for display
+  (when (git-call-process-display-error "push" remote)
+    (message "Pushed to remote: %s" remote)))
+
+(defun git-fetch (&optional remote)
+  "Fetch from REMOTE. Use \\[current-prefix-arg] to interactively set REMOTE."
+  (interactive
+   (list (or (and current-prefix-arg
+		  (git-ask-remote "Fetch from remote: "))
+	     "origin")))
+  ;; FIXME: could collect some status data for display
+  (when (git-call-process-display-error "fetch" remote)
+    (message "Fetched from remote: %s" remote)))
+
+(defun git-pull (&optional remote)
+  "Pull from REMOTE. Use \\[current-prefix-arg] to interactively set REMOTE."
+  (interactive
+   (list (or (and current-prefix-arg
+		  (git-ask-remote "Pull from remote: "))
+	     "origin")))
+  (let ((not-clean
+	 (ewoc-collect git-status (lambda (info &optional state)
+				    (setq state (git-fileinfo->state info))
+				    (or (eq state 'modified)
+					(eq state 'added)
+					(eq state 'deleted)
+					(eq state 'unmerged))))))
+    (if not-clean
+	(error "Error: Can't pull while in unclean state (commit all first)."))
+    (unless git-status (error "Not in git-status buffer."))
+    ;; FIXME: could collect some status data for display
+    (when (git-call-process-display-error "pull" remote)
+      (message "Pulled from remote: %s" remote))))
+
 (defun git-help ()
   "Display help for Git mode."
   (interactive)
-- 
1.7.4.1

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

* [PATCH v4] contrib/emacs/git.el: Add user functions for push, pull, fetch
  2011-04-03 17:48       ` [PATCH v3] " jari.aalto
@ 2011-04-14 21:07         ` jari.aalto
  0 siblings, 0 replies; 6+ messages in thread
From: jari.aalto @ 2011-04-14 21:07 UTC (permalink / raw)
  To: git; +Cc: Jari Aalto

From: Jari Aalto <jari.aalto@cante.net>

Signed-off-by: Jari Aalto <jari.aalto@cante.net>
---
 contrib/emacs/git.el |  110 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 109 insertions(+), 1 deletions(-)

  [v2]
  ** This fixes the pull message. The only change is last line:
  ** (message "Pulled from remote: %s" remote)))

  [v3] Fixes commented by <julliard@winehq.org>
  ** Extra C-a keymap binding removed
  ** Check success status before displaying message
  ** no need to refresh the status files on push or fetch

  [v4]
  ** Parse remotes from .git/config and offer them as completions (push/pull)

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 65c95d9..97d2484 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -1,6 +1,7 @@
 ;;; git.el --- A user interface for git
 
 ;; Copyright (C) 2005, 2006, 2007, 2008, 2009 Alexandre Julliard <julliard@winehq.org>
+;; Copyright (C) 2010 Jari Aalto <jari.aalto@cante.net>
 
 ;; Version: 1.0
 
@@ -33,11 +34,14 @@
 ;;
 ;; To start: `M-x git-status'
 ;;
+;; RUDIMENTARY
+;; - fetch/pull. Be sure to start gpg-agent, ssh-agent prior emacs
+;;   to access ssh Git remotes.
+;;
 ;; TODO
 ;;  - diff against other branch
 ;;  - renaming files from the status buffer
 ;;  - creating tags
-;;  - fetch/pull
 ;;  - revlist browser
 ;;  - git-show-branch browser
 ;;
@@ -384,6 +388,25 @@ the process output as a string, or nil if the git command failed."
   (git-get-string-sha1
    (git-call-process-string "rev-parse" rev)))
 
+(defun git-root ()
+  "Return root of git directory. Start from current dir way up."
+  (let* ((dir (file-name-as-directory default-directory))
+	 (try (format "%s%s" dir ".git")))
+    (while (and dir
+		(not (file-directory-p try)))
+      (if (string-match "^\\(.*/\\).+$" dir)
+	  (setq dir (match-string 1 dir)
+		try (format "%s%s" dir ".git"))
+	(setq dir nil
+	      try nil)))
+    try))
+
+(defsubst git-config-file ()
+  "Return 'config' file location."
+  (let ((dir (git-root)))
+    (if dir
+	(format "%s/config" dir))))
+
 (defun git-config (key)
   "Retrieve the value associated to KEY in the git repository config file."
   (let ((str (git-call-process-string "config" key)))
@@ -1527,6 +1550,7 @@ amended version of it."
 
 (unless git-status-mode-map
   (let ((map (make-keymap))
+        (remote-map (make-sparse-keymap))
         (commit-map (make-sparse-keymap))
         (diff-map (make-sparse-keymap))
         (toggle-map (make-sparse-keymap)))
@@ -1554,6 +1578,7 @@ amended version of it."
     (define-key map "P"   'git-prev-unmerged-file)
     (define-key map "q"   'git-status-quit)
     (define-key map "r"   'git-remove-file)
+    (define-key map "R"   remote-map)
     (define-key map "t"    toggle-map)
     (define-key map "T"   'git-toggle-all-marks)
     (define-key map "u"   'git-unmark-file)
@@ -1562,6 +1587,11 @@ amended version of it."
     (define-key map "x"   'git-remove-handled)
     (define-key map "\C-?" 'git-unmark-file-up)
     (define-key map "\M-\C-?" 'git-unmark-all)
+    ; remotes
+    (define-key remote-map "R" 'git-pull)  ; retrieve "RR"
+    (define-key remote-map "r" 'git-pull)  ; retrieve "Rr" (synonym)
+    (define-key remote-map "p" 'git-push)
+    (define-key remote-map "f" 'git-fetch)
     ; the commit submap
     (define-key commit-map "\C-a" 'git-amend-commit)
     (define-key commit-map "\C-b" 'git-branch)
@@ -1614,6 +1644,10 @@ amended version of it."
       ["Interactive Diff File" git-diff-file-idiff t]
       ["Log" git-log-file t]
       "--------"
+      ["Push" git-push t]
+      ["Pull" git-pull t]
+      ["Fetch" git-fetch t]
+      "--------"
       ["Mark" git-mark-file t]
       ["Mark All" git-mark-all t]
       ["Unmark" git-unmark-file t]
@@ -1696,6 +1730,80 @@ Meant to be used in `after-save-hook'."
             (git-call-process nil "add" "--refresh" "--" filename)
             (git-update-status-files (list filename))))))))
 
+(defun git-remote-parse ()
+  "Parse remotes from current point forward. Return list."
+  (let (list)
+    ;; [remote "origin"]
+    (while (re-search-forward "^\\[remote[[:space:]]+\"\\([^\"]+\\)" nil t)
+      (push (match-string-no-properties 1) list))
+    list))
+
+(defun git-remote-list ()
+  "Return list of remotes from Git configuration."
+  (with-temp-buffer
+    (insert-file-contents-literally (git-config-file))
+    (goto-char (point-min))
+    (git-remote-parse)))
+
+(defun git-ask-remote (prompt)
+  "Read remote with PROMPT."
+  (let ((list (git-remote-list))
+	(default "origin")
+	ret)
+    (unless (member default list)
+      (setq default (car list)))
+    (setq ret
+	  (completing-read prompt
+			   list
+			   (not 'predicate)
+			   'require-match
+			   (not 'default)
+			   (not 'history)
+			   default))
+    (if (string-match "^[ \t\r\n]*$" ret)
+	(setq ret default))
+    ret))
+
+(defun git-push (&optional remote)
+  "Pull to REMOTE. Use \\[current-prefix-arg] to interactively set REMOTE."
+  (interactive
+   (list (or (and current-prefix-arg
+		  (git-ask-remote "Push to remote: "))
+	     "origin")))
+  ;; FIXME: could collect some status data for display
+  (when (git-call-process-display-error "push" remote)
+    (message "Pushed to remote: %s" remote)))
+
+(defun git-fetch (&optional remote)
+  "Fetch from REMOTE. Use \\[current-prefix-arg] to interactively set REMOTE."
+  (interactive
+   (list (or (and current-prefix-arg
+		  (git-ask-remote "Fetch from remote: "))
+	     "origin")))
+  ;; FIXME: could collect some status data for display
+  (when (git-call-process-display-error "fetch" remote)
+    (message "Fetched from remote: %s" remote)))
+
+(defun git-pull (&optional remote)
+  "Pull from REMOTE. Use \\[current-prefix-arg] to interactively set REMOTE."
+  (interactive
+   (list (or (and current-prefix-arg
+		  (git-ask-remote "Pull from remote: "))
+	     "origin")))
+  (let ((not-clean
+	 (ewoc-collect git-status (lambda (info &optional state)
+				    (setq state (git-fileinfo->state info))
+				    (or (memq state '(added
+						      deleted
+						      modified
+						      unmerged)))))))
+    (if not-clean
+	(error "Error: Can't pull while in unclean state (commit all first)."))
+    (unless git-status (error "Not in git-status buffer."))
+    ;; FIXME: could collect some status data for display
+    (when (git-call-process-display-error "pull" remote)
+      (message "Pulled from remote: %s" remote))))
+
 (defun git-help ()
   "Display help for Git mode."
   (interactive)
-- 
1.7.4.1

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

end of thread, other threads:[~2011-04-14 21:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-22 13:30 [PATCH] git.el: Add new user functions for push, pull, fetch jari.aalto
2011-03-22 14:36 ` [PATCH v2] contrib/emacs/git.el: Add " jari.aalto
2011-04-03 16:13   ` Jari Aalto
2011-04-03 17:27     ` Alexandre Julliard
2011-04-03 17:48       ` [PATCH v3] " jari.aalto
2011-04-14 21:07         ` [PATCH v4] " jari.aalto

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 NNTP newsgroup(s).