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:
parent
9db7719b96
commit
dad98cea88
1 changed files with 16 additions and 10 deletions
26
magit.el
26
magit.el
|
@ -1477,8 +1477,14 @@ Please see the manual for a complete description of Magit.
|
||||||
|
|
||||||
(defun magit-insert-staged-changes ()
|
(defun magit-insert-staged-changes ()
|
||||||
(let ((magit-hide-diffs t))
|
(let ((magit-hide-diffs t))
|
||||||
(magit-insert-section 'staged "Staged changes:" 'magit-wash-diffs
|
(if no-commit
|
||||||
magit-git-executable "diff" "--cached")))
|
(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
|
;;; Logs and Commits
|
||||||
|
|
||||||
|
@ -1618,7 +1624,11 @@ in log buffer."
|
||||||
(magit-create-buffer-sections
|
(magit-create-buffer-sections
|
||||||
(magit-with-section 'status nil
|
(magit-with-section 'status nil
|
||||||
(let* ((branch (magit-get-current-branch))
|
(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
|
(if remote
|
||||||
(insert (format "Remote: %s %s\n"
|
(insert (format "Remote: %s %s\n"
|
||||||
remote (magit-get "remote" remote "url"))))
|
remote (magit-get "remote" remote "url"))))
|
||||||
|
@ -1626,12 +1636,8 @@ in log buffer."
|
||||||
(propertize (or branch "(detached)")
|
(propertize (or branch "(detached)")
|
||||||
'face 'magit-branch)
|
'face 'magit-branch)
|
||||||
(abbreviate-file-name default-directory)))
|
(abbreviate-file-name default-directory)))
|
||||||
(insert
|
(insert (format "Head: %s\n"
|
||||||
(format
|
(if no-commit "nothing commited (yet)" head)))
|
||||||
"Head: %s\n"
|
|
||||||
(magit-shell
|
|
||||||
"%s log --max-count=1 --abbrev-commit --pretty=oneline"
|
|
||||||
magit-git-executable)))
|
|
||||||
(let ((merge-heads (magit-file-lines ".git/MERGE_HEAD")))
|
(let ((merge-heads (magit-file-lines ".git/MERGE_HEAD")))
|
||||||
(if merge-heads
|
(if merge-heads
|
||||||
(insert (format "Merging: %s\n"
|
(insert (format "Merging: %s\n"
|
||||||
|
@ -1648,7 +1654,7 @@ in log buffer."
|
||||||
(magit-insert-pending-commits)
|
(magit-insert-pending-commits)
|
||||||
(when remote
|
(when remote
|
||||||
(magit-insert-unpulled-commits remote branch))
|
(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
|
(magit-insert-unstaged-changes
|
||||||
(if staged "Unstaged changes:" "Changes:"))
|
(if staged "Unstaged changes:" "Changes:"))
|
||||||
(if staged
|
(if staged
|
||||||
|
|
Loading…
Reference in a new issue