(changes)

This commit is contained in:
Marius Vollmer 2008-08-01 16:04:52 +03:00
parent 6ef85709e9
commit 507abe1a96
3 changed files with 88 additions and 17 deletions

View file

@ -57,6 +57,57 @@
(defun gits-get (key)
(gits-shell "git-config %s" key))
;;; Running asynchronous commands
(defvar gits-process nil)
(defun gits-run (cmd &rest args)
(or (not gits-process)
(error "Git is already running."))
(let ((dir default-directory)
(buf (get-buffer-create "*git-process*")))
(save-excursion
(set-buffer buf)
(setq default-directory dir)
(erase-buffer)
(setq gits-process (apply 'start-process "git" buf cmd args))
(set-process-sentinel gits-process 'gits-process-sentinel))))
(defun gits-process-sentinel (process event)
(cond ((string= event "finished\n")
(message "Git finished.")
(setq gits-process nil))
((string= event "killed\n")
(message "Git was killed.")
(setq gits-process nil))
((string-match "exited abnormally" event)
(message "Git failed.")
(setq gits-process nil))
(t
(message "Git is weird.")))
(gits-update-status))
;;; Status
(defun gits-update-status ()
(let ((buf (get-buffer "*git-status*")))
(save-excursion
(set-buffer buf)
(erase-buffer)
(insert (format "Repository: %s\n"
(abbreviate-file-name default-directory)))
(insert (format "Branch: %s\n"
(gits-shell "git-symbolic-ref -q HEAD")))
(let ((origin (gits-get "remote.origin.url")))
(if origin
(insert (format "Origin: %s\n" origin))))
(insert "\n")
(insert "Local changes:\n")
(call-process-shell-command "git diff" nil t)
(insert "\n")
(insert "Staged changes:\n")
(call-process-shell-command "git diff --cached" nil t))))
;;; Main
(defun git-status (cwd)
@ -66,24 +117,25 @@
(error "Not a git repository."))
(let ((buf (get-buffer-create "*git-status*")))
(switch-to-buffer buf)
(save-excursion
(set-buffer buf)
(setq default-directory dir)
(erase-buffer)
(insert (format "Repository: %s\n"
(abbreviate-file-name default-directory)))
(insert (format "Branch: %s\n"
(gits-shell "git-symbolic-ref -q HEAD")))
(let ((origin (gits-get "remote.origin.url")))
(if origin
(insert (format "Origin: %s\n" origin))))
(insert "\n")
(insert "Local changes:\n")
(call-process-shell-command "git diff" nil t)
(insert "\n")
(insert "Staged changes:\n")
(call-process-shell-command "git diff --cached" nil t)))))
(setq default-directory dir)
(gits-update-status))))
(defun git-status-here ()
(interactive)
(git-status default-directory))
(defun git-pull ()
(interactive)
(gits-run "git-pull" "origin" "master"))
(defun git-push ()
(interactive)
(gits-run "git-push" "origin"))
(defun git-stage-all ()
(interactive)
(gits-run "git-add" "."))
(defun git-commit ()
(interactive)
(gits-run "git-commit" "-m" "(changes)"))

19
git-status.el~ Normal file
View file

@ -0,0 +1,19 @@
;;; git-status -- control git from Emacs.
;; Copyright (C) 2008 Marius Vollmer
;;
;; Git-status is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation; either version 3, or (at your
;; option) any later version.
;;
;; Git-status is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

0
test/FOO Normal file
View file