help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Git never commits, Magit never pushes


From: Jambunathan K
Subject: Re: Git never commits, Magit never pushes
Date: Sun, 03 Apr 2011 14:45:25 +0530
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (windows-nt)

> Hi Jambunathan,
>
> Jambunathan K wrote:
>> Have you tried vc-git that comes bundled with emacs.
>
> Now, yes. But it still does not interest me that much, as there is no
> interactive diff, which one tool I really need to compare buffers before
> committing.

I use ediff with git all the time. 

Put vc-ediff.el (attached with this mail) in the load-path. Add the
following code to .emacs.

Now "x" on a vc-dir would hide update and unregistered files. (It will
only show added/modified files)

"C-x C-v =" on a version controlled buffer would launch ediff window.

I have been using this setup for a while so I know it works. If
something is broken it is possible that I haven't copy/pasted some stuff
from my init file. 

--8<---------------cut here---------------start------------->8---
(require 'vc-ediff)

(add-hook  'vc-dir-mode-hook
           (lambda nil
             (define-key vc-dir-mode-map "x" 'my-vc-dir-hide-up-to-date)))

(defun my-vc-dir-hide-up-to-date ()
  (interactive)
  (vc-dir-hide-up-to-date)
  (vc-dir-hide-unregistered))

(defun vc-dir-hide-unregistered ()
  "Hide unregistered items from display."
  (interactive)
  (let ((crt (ewoc-nth vc-ewoc -1))
        (first (ewoc-nth vc-ewoc 0)))
    ;; Go over from the last item to the first and remove the
    ;; unregistered files and directories with no child files.
    (while (not (eq crt first))
      (let* ((data (ewoc-data crt))
             (dir (vc-dir-fileinfo->directory data))
             (next (ewoc-next vc-ewoc crt))
             (prev (ewoc-prev vc-ewoc crt))
             ;; ewoc-delete does not work without this...
             (inhibit-read-only t))
        (when (or
               ;; Remove directories with no child files.
               (and dir
                    (or
                     ;; Nothing follows this directory.
                     (not next)
                     ;; Next item is a directory.
                     (vc-dir-fileinfo->directory (ewoc-data next))))
               ;; Remove files in the unregistered state.
               (eq (vc-dir-fileinfo->state data) 'unregistered))
          (ewoc-delete vc-ewoc crt))
        (setq crt prev)))))


(defun my-ediff-revision (file rev1 &optional rev2)
  "Run Ediff by comparing 'master' against the 'current'."
  (find-file file)
  (if (and (buffer-modified-p)
           (y-or-n-p (format "Buffer %s is modified. Save buffer? "
                             (buffer-name))))
      (save-buffer (current-buffer)))

  (ediff-load-version-control)

  (funcall
   (intern (format "ediff-%S-internal" ediff-version-control-package))
   rev1 rev2 nil))

(defun my-vc-diff (&optional arg)
  (interactive "P")
  (call-interactively
   (cond (arg (lambda nil (interactive) (vc-diff nil)))
         (t (lambda nil (interactive)
              (my-ediff-revision (buffer-file-name)
                                 (read-string "revision? " "HEAD" nil "HEAD")
                                 ""))))))

(define-key vc-prefix-map "=" 'my-vc-diff)

--8<---------------cut here---------------end--------------->8---

> I did not find yet, though, how to push it to the Git repo. 

C-x v v commits to the local branch. I generally push to the remote repo
from the shell.


Attachment: vc-ediff.el
Description: vc-ediff.el

-- 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]