Handle fresh empty repository.

It was imposible to see what was staged for a first commit on a fresh
git repository. The only visible lines was fatal error messages from
git. Now diff against null tree object is shown in magit status buffer
if nothing was yet commited to the repository. The cost is 15-byte
object added to the repo, but it shuld disappear on first call to git
gc.
This commit is contained in:
Alexey Voinov 2009-02-04 17:54:30 +03:00
parent 9db7719b96
commit dad98cea88

View file

@ -1477,8 +1477,14 @@ Please see the manual for a complete description of Magit.
(defun magit-insert-staged-changes ()
(let ((magit-hide-diffs t))
(magit-insert-section 'staged "Staged changes:" 'magit-wash-diffs
magit-git-executable "diff" "--cached")))
(if no-commit
(let ((null-tree (magit-shell "git mktree </dev/null")))
(magit-insert-section 'staged "Staged changes:" 'magit-wash-diffs
magit-git-executable "diff" "--cached"
null-tree))
(magit-insert-section 'staged "Staged changes:" 'magit-wash-diffs
magit-git-executable "diff" "--cached"))))
;;; Logs and Commits
@ -1618,7 +1624,11 @@ in log buffer."
(magit-create-buffer-sections
(magit-with-section 'status nil
(let* ((branch (magit-get-current-branch))
(remote (and branch (magit-get "branch" branch "remote"))))
(remote (and branch (magit-get "branch" branch "remote")))
(head (magit-shell
"%s log --max-count=1 --abbrev-commit --pretty=oneline"
magit-git-executable))
(no-commit (string-match "fatal: bad default revision" head)))
(if remote
(insert (format "Remote: %s %s\n"
remote (magit-get "remote" remote "url"))))
@ -1626,12 +1636,8 @@ in log buffer."
(propertize (or branch "(detached)")
'face 'magit-branch)
(abbreviate-file-name default-directory)))
(insert
(format
"Head: %s\n"
(magit-shell
"%s log --max-count=1 --abbrev-commit --pretty=oneline"
magit-git-executable)))
(insert (format "Head: %s\n"
(if no-commit "nothing commited (yet)" head)))
(let ((merge-heads (magit-file-lines ".git/MERGE_HEAD")))
(if merge-heads
(insert (format "Merging: %s\n"
@ -1648,7 +1654,7 @@ in log buffer."
(magit-insert-pending-commits)
(when remote
(magit-insert-unpulled-commits remote branch))
(let ((staged (magit-anything-staged-p)))
(let ((staged (or no-commit (magit-anything-staged-p))))
(magit-insert-unstaged-changes
(if staged "Unstaged changes:" "Changes:"))
(if staged