The "Untracked files" section is back, with better ignoring.

* magit.el (magit-wash-untracked-file, magit-wash-untracked-files,
magit-insert-untracked-files): New.
(magit-insert-unstaged-changes): Don't include other files in output.
(magit-mode-map): '1' jumps to untracked files instead of unpulled
changes.
(magit-stage-item, magit-discard-item, magit-visit-item):
Handle untracked files.
(magit-ignore-file): New.
(magit-ignore-item): Use it.
(magit-ignore-item-locally): New.
(magit-mode-map): Bind it to "I".
* magit.texi: Document it all.
This commit is contained in:
Marius Vollmer 2008-10-12 02:10:06 +03:00
parent 871bf2f2d6
commit 138ac10b34
2 changed files with 62 additions and 15 deletions

View file

@ -779,7 +779,7 @@ Many Magit faces inherit from this one by default."
;; We define individual functions (instead of using lambda etc) so ;; We define individual functions (instead of using lambda etc) so
;; that the online help can show something meaningful. ;; that the online help can show something meaningful.
(magit-define-section-jumper unpulled "Unpulled commits") (magit-define-section-jumper untracked "Untracked files")
(magit-define-section-jumper unstaged "Unstaged changes") (magit-define-section-jumper unstaged "Unstaged changes")
(magit-define-section-jumper staged "Staged changes") (magit-define-section-jumper staged "Staged changes")
(magit-define-section-jumper unpushed "Unpushed commits") (magit-define-section-jumper unpushed "Unpushed commits")
@ -790,7 +790,7 @@ Many Magit faces inherit from this one by default."
(define-key map (kbd "n") 'magit-goto-next-section) (define-key map (kbd "n") 'magit-goto-next-section)
(define-key map (kbd "p") 'magit-goto-previous-section) (define-key map (kbd "p") 'magit-goto-previous-section)
(define-key map (kbd "TAB") 'magit-cycle-section) (define-key map (kbd "TAB") 'magit-cycle-section)
(define-key map (kbd "1") 'magit-jump-to-unpulled) (define-key map (kbd "1") 'magit-jump-to-untracked)
(define-key map (kbd "2") 'magit-jump-to-unstaged) (define-key map (kbd "2") 'magit-jump-to-unstaged)
(define-key map (kbd "3") 'magit-jump-to-staged) (define-key map (kbd "3") 'magit-jump-to-staged)
(define-key map (kbd "4") 'magit-jump-to-unpushed) (define-key map (kbd "4") 'magit-jump-to-unpushed)
@ -801,6 +801,8 @@ Many Magit faces inherit from this one by default."
(define-key map (kbd "u") 'magit-unstage-item) (define-key map (kbd "u") 'magit-unstage-item)
(define-key map (kbd "U") 'magit-unstage-all) (define-key map (kbd "U") 'magit-unstage-all)
(define-key map (kbd "i") 'magit-ignore-item) (define-key map (kbd "i") 'magit-ignore-item)
(define-key map (kbd "I") 'magit-ignore-item-locally)
(define-key map (kbd "i") 'magit-ignore-item)
(define-key map (kbd "?") 'magit-describe-item) (define-key map (kbd "?") 'magit-describe-item)
(define-key map (kbd ".") 'magit-mark-item) (define-key map (kbd ".") 'magit-mark-item)
(define-key map (kbd "=") 'magit-diff-with-mark) (define-key map (kbd "=") 'magit-diff-with-mark)
@ -864,6 +866,7 @@ Many Magit faces inherit from this one by default."
["Revert" magit-revert-item t] ["Revert" magit-revert-item t]
"---" "---"
["Ignore" magit-ignore-item t] ["Ignore" magit-ignore-item t]
["Ignore locally" magit-ignore-item-locally t]
["Discard" magit-discard-item t] ["Discard" magit-discard-item t]
["Reset head" magit-reset-head t] ["Reset head" magit-reset-head t]
["Reset working tree" magit-reset-working-tree t] ["Reset working tree" magit-reset-working-tree t]
@ -1019,6 +1022,27 @@ Please see the manual for a complete description of Magit.
(interactive) (interactive)
(magit-for-all-buffers #'magit-refresh-buffer default-directory)) (magit-for-all-buffers #'magit-refresh-buffer default-directory))
;;; Untracked files
(defun magit-wash-untracked-file ()
(if (looking-at "^? \\(.*\\)$")
(let ((file (match-string-no-properties 1)))
(delete-region (point) (+ (line-end-position) 1))
(magit-with-section file 'file
(magit-set-section-info file)
(insert "\t" file "\n"))
t)
nil))
(defun magit-wash-untracked-files ()
(magit-wash-sequence #'magit-wash-untracked-file))
(defun magit-insert-untracked-files ()
(magit-insert-section 'untracked "Untracked files:"
'magit-wash-untracked-files
magit-collapse-threshold
"git" "ls-files" "-t" "--others" "--exclude-standard"))
;;; Diffs and Hunks ;;; Diffs and Hunks
(defun magit-diff-line-file () (defun magit-diff-line-file ()
@ -1200,7 +1224,7 @@ Please see the manual for a complete description of Magit.
(let ((magit-hide-diffs t)) (let ((magit-hide-diffs t))
(magit-insert-section 'unstaged title 'magit-wash-diffs (magit-insert-section 'unstaged title 'magit-wash-diffs
magit-collapse-threshold magit-collapse-threshold
"sh" "-c" "git ls-files -t --others --exclude-standard; git diff"))) "git" "diff")))
(defun magit-insert-staged-changes () (defun magit-insert-staged-changes ()
(let ((magit-hide-diffs t)) (let ((magit-hide-diffs t))
@ -1330,6 +1354,7 @@ Please see the manual for a complete description of Magit.
(if rebase (if rebase
(insert (apply 'format "Rebasing: %s (%s of %s)\n" rebase)))) (insert (apply 'format "Rebasing: %s (%s of %s)\n" rebase))))
(insert "\n") (insert "\n")
(magit-insert-untracked-files)
(magit-insert-pending-changes) (magit-insert-pending-changes)
(magit-insert-pending-commits) (magit-insert-pending-commits)
(when remote (when remote
@ -1361,7 +1386,7 @@ Please see the manual for a complete description of Magit.
"Add the item at point to the staging area." "Add the item at point to the staging area."
(interactive) (interactive)
(magit-section-action (item info "stage") (magit-section-action (item info "stage")
((unstaged file) ((untracked file)
(magit-run "git" "add" info)) (magit-run "git" "add" info))
((unstaged diff hunk) ((unstaged diff hunk)
(if (magit-hunk-item-is-conflict-p item) (if (magit-hunk-item-is-conflict-p item)
@ -1962,18 +1987,29 @@ Prefix arg means justify as well."
;;; Miscellaneous ;;; Miscellaneous
(defun magit-ignore-file (file edit local)
(let ((ignore-file (if local ".git/info/exclude" ".gitignore")))
(if edit
(setq file (read-string "File to ignore: " file)))
(append-to-file (concat "/" file "\n") nil ignore-file)
(magit-need-refresh)))
(defun magit-ignore-item () (defun magit-ignore-item ()
(interactive) (interactive)
(magit-section-action (item info "ignore") (magit-section-action (item info "ignore")
((unstaged file) ((untracked file)
(append-to-file (concat "/" info "\n") (magit-ignore-file info current-prefix-arg nil))))
nil ".gitignore")
(magit-need-refresh)))) (defun magit-ignore-item-locally ()
(interactive)
(magit-section-action (item info "ignore")
((untracked file)
(magit-ignore-file info current-prefix-arg t))))
(defun magit-discard-item () (defun magit-discard-item ()
(interactive) (interactive)
(magit-section-action (item info "discard") (magit-section-action (item info "discard")
((unstaged file) ((untracked file)
(if (yes-or-no-p (format "Delete %s? " info)) (if (yes-or-no-p (format "Delete %s? " info))
(magit-run "rm" info))) (magit-run "rm" info)))
((unstaged diff hunk) ((unstaged diff hunk)
@ -2002,7 +2038,7 @@ Prefix arg means justify as well."
(defun magit-visit-item () (defun magit-visit-item ()
(interactive) (interactive)
(magit-section-action (item info "visit") (magit-section-action (item info "visit")
((unstaged file) ((untracked file)
(find-file info)) (find-file info))
((diff) ((diff)
(find-file (magit-diff-item-file item))) (find-file (magit-diff-item-file item)))

View file

@ -104,6 +104,8 @@ states of the section: fully visible, fully hidden (expect for the
first line), and collapsed, where only the first lines of the children first line), and collapsed, where only the first lines of the children
are visible. You can also control the visibility of sub-sections in are visible. You can also control the visibility of sub-sections in
this way. this way.
The first section shows @emph{Untracked files}, if there are any. See
@ref{Untracked files} for more details.
Two section show your local changes. They are explained fully in the Two section show your local changes. They are explained fully in the
next chapter, @ref{Staging and Committing}. next chapter, @ref{Staging and Committing}.
@ -113,12 +115,25 @@ status buffer shows the differences between the current branch and the
tracking branch. See @ref{Pushing and Pulling} for more information. tracking branch. See @ref{Pushing and Pulling} for more information.
Typing a digit in the status buffer will move point to a section Typing a digit in the status buffer will move point to a section
header: @kbd{1} will move to @emph{Unpulled commits}, @kbd{2} will move header: @kbd{1} will move to @emph{Untracked files}, @kbd{2} will move
to @emph{Unstaged changes} or @emph{Changes}, @kbd{3} will move to to @emph{Unstaged changes} or @emph{Changes}, @kbd{3} will move to
@emph{Staged changes}, and @kbd{4} will move to @emph{Unpushed @emph{Staged changes}, and @kbd{4} will move to @emph{Unpushed
commits}. Note that these relations are fixed, @kbd{3} always moves commits}. Note that these relations are fixed, @kbd{3} always moves
to @emph{Unstaged changes}, not the third visible section. to @emph{Unstaged changes}, not the third visible section.
@node Untracked files
@chapter Untracked files
Untracked files are shown in the @emph{Untracked changes} section.
You can instruct Git to ignore them by typing @kbd{i}. This will add
the filename to the @code{.gitignore} file. Typing @kbd{C-u i} will
ask you for the name of the file to ignore. This is useful to ignore
whole directories, for example. The @kbd{I} command is similar to
@kbd{i} but will add the file to @code{.git/info/exclude} instead.
To delete a untracked file forever, use @kbd{k}.
@node Staging and Committing @node Staging and Committing
@chapter Staging and Committing @chapter Staging and Committing
@ -137,10 +152,6 @@ changes} section shows the changes that will be included in the next
commit, while the @emph{Unstaged changes} section shows the changes commit, while the @emph{Unstaged changes} section shows the changes
that will be left out. that will be left out.
Untracked files are shown as @emph{New} in the @emph{Changes} or
@emph{Unstaged changes} section. You can instruct Git to ignore them
by typing @kbd{i}.
You can discard uncommitted changes by moving point into a hunk and You can discard uncommitted changes by moving point into a hunk and
typing @kbd{k}. typing @kbd{k}.