(changes)

This commit is contained in:
Marius Vollmer 2008-08-03 21:33:25 +03:00
parent 507abe1a96
commit bdc23da0f3
2 changed files with 53 additions and 20 deletions

1
.#git-status.el Symbolic link
View file

@ -0,0 +1 @@
mvo@manamana.16547:1212169673

View file

@ -46,6 +46,17 @@
(substring str 0 (- (length str) 1)) (substring str 0 (- (length str) 1))
str)))) str))))
(defun gits-concat-with-delim (delim seqs)
(cond ((null seqs)
nil)
((null (cdr seqs))
(car seqs))
(t
(concat (car seqs) delim (gits-concat-with-delim delim (cdr seqs))))))
(defun gits-get (&rest keys)
(gits-shell "git-config %s" (gits-concat-with-delim "." keys)))
(defun gits-get-top-dir (cwd) (defun gits-get-top-dir (cwd)
(let* ((cwd (expand-file-name cwd)) (let* ((cwd (expand-file-name cwd))
(git-dir (gits-shell "cd '%s' && git-rev-parse --git-dir 2>/dev/null" (git-dir (gits-shell "cd '%s' && git-rev-parse --git-dir 2>/dev/null"
@ -54,8 +65,21 @@
(file-name-as-directory (or (file-name-directory git-dir) cwd)) (file-name-as-directory (or (file-name-directory git-dir) cwd))
nil))) nil)))
(defun gits-get (key) (defun gits-get-ref (ref)
(gits-shell "git-config %s" key)) (gits-shell "git-symbolic-ref -q %s" ref))
(defun gits-get-current-branch ()
(let* ((head (gits-get-ref "HEAD"))
(pos (and head (string-match "^refs/heads/" head))))
(if pos
(substring head 11)
nil)))
(defun gits-read-top-dir (prefix)
(let ((dir (gits-get-top-dir default-directory)))
(if prefix
(gits-get-top-dir (read-directory-name "Git repository: " dir))
dir)))
;;; Running asynchronous commands ;;; Running asynchronous commands
@ -96,11 +120,20 @@
(erase-buffer) (erase-buffer)
(insert (format "Repository: %s\n" (insert (format "Repository: %s\n"
(abbreviate-file-name default-directory))) (abbreviate-file-name default-directory)))
(insert (format "Branch: %s\n" (let ((branch (gits-get-current-branch)))
(gits-shell "git-symbolic-ref -q HEAD"))) (insert (format "Branch: %s\n"
(let ((origin (gits-get "remote.origin.url"))) (or branch "(detached)")))
(if origin (if branch
(insert (format "Origin: %s\n" origin)))) (let ((remote (gits-get "branch" branch "remote")))
(if remote
(let* ((push (gits-get "remote" remote "push"))
(pull (gits-get "remote" remote "fetch"))
(desc (if (equal push pull)
push
(format "%s -> %s" pull push))))
(insert (format "Remote: %s\n %s\n"
desc
(gits-get "remote" remote "url"))))))))
(insert "\n") (insert "\n")
(insert "Local changes:\n") (insert "Local changes:\n")
(call-process-shell-command "git diff" nil t) (call-process-shell-command "git diff" nil t)
@ -110,27 +143,26 @@
;;; Main ;;; Main
(defun git-status (cwd) (defun git-status (dir)
(interactive "DDirectory: ") (interactive (list (gits-read-top-dir current-prefix-arg)))
(let ((dir (gits-get-top-dir cwd))) (let ((buf (get-buffer-create "*git-status*")))
(or dir (switch-to-buffer buf)
(error "Not a git repository.")) (setq default-directory dir)
(let ((buf (get-buffer-create "*git-status*"))) (gits-update-status)))
(switch-to-buffer buf)
(setq default-directory dir)
(gits-update-status))))
(defun git-status-here () (defun git-show-status ()
(interactive) (interactive)
(git-status default-directory)) (let ((buf (get-buffer-create "*git-status*")))
(switch-to-buffer buf)
(gits-update-status)))
(defun git-pull () (defun git-pull ()
(interactive) (interactive)
(gits-run "git-pull" "origin" "master")) (gits-run "git-pull"))
(defun git-push () (defun git-push ()
(interactive) (interactive)
(gits-run "git-push" "origin")) (gits-run "git-push"))
(defun git-stage-all () (defun git-stage-all ()
(interactive) (interactive)