1 ;; stgit.el: An emacs mode for StGit
3 ;; Copyright (C) 2007 David Kågedal <davidk@lysator.liu.se>
5 ;; To install: put this file on the load-path and place the following
6 ;; in your .emacs file:
10 ;; To start: `M-x stgit'
17 "Manage StGit patches for the tree in DIR."
18 (interactive "DDirectory: \n")
19 (switch-to-stgit-buffer (git-get-top-dir dir))
22 (unless (fboundp 'git-get-top-dir)
23 (defun git-get-top-dir (dir)
24 "Retrieve the top-level directory of a git tree."
25 (let ((cdup (with-output-to-string
26 (with-current-buffer standard-output
28 (unless (eq 0 (call-process "git" nil t nil
29 "rev-parse" "--show-cdup"))
30 (error "Cannot find top-level git tree for %s" dir))))))
31 (expand-file-name (concat (file-name-as-directory dir)
32 (car (split-string cdup "\n")))))))
34 (defun stgit-refresh-git-status (&optional dir)
35 "If it exists, refresh the `git-status' buffer belonging to
36 directory DIR or `default-directory'"
37 (when (and (fboundp 'git-find-status-buffer)
38 (fboundp 'git-refresh-status))
39 (let* ((top-dir (git-get-top-dir (or dir default-directory)))
40 (git-status-buffer (and top-dir (git-find-status-buffer top-dir))))
41 (when git-status-buffer
42 (with-current-buffer git-status-buffer
43 (git-refresh-status))))))
45 (defun stgit-find-buffer (dir)
46 "Return the buffer displaying StGit patches for DIR, or nil if none."
47 (setq dir (file-name-as-directory dir))
48 (let ((buffers (buffer-list)))
50 (not (with-current-buffer (car buffers)
51 (and (eq major-mode 'stgit-mode)
52 (string= default-directory dir)))))
53 (setq buffers (cdr buffers)))
54 (and buffers (car buffers))))
56 (defun switch-to-stgit-buffer (dir)
57 "Switch to a (possibly new) buffer displaying StGit patches for DIR."
58 (setq dir (file-name-as-directory dir))
59 (let ((buffer (stgit-find-buffer dir)))
60 (switch-to-buffer (or buffer
61 (create-stgit-buffer dir)))))
63 (defstruct (stgit-patch)
64 status name desc empty files-ewoc)
66 (defun stgit-patch-pp (patch)
67 (let* ((status (stgit-patch-status patch))
69 (name (stgit-patch-name patch))
70 (face (cdr (assq status stgit-patch-status-face-alist))))
76 (if (memq name stgit-marked-patches)
78 (if (memq status '(index work))
79 (insert (propertize (if (eq status 'index) "Index" "Work tree")
81 (insert (format "%-30s"
82 (propertize (symbol-name name) 'face face))
84 (if (stgit-patch-empty patch) "(empty) " "")
85 (propertize (or (stgit-patch-desc patch) "")
86 'face 'stgit-description-face)))
88 (put-text-property start (point) 'entry-type 'patch)
89 (when (memq name stgit-expanded-patches)
90 (stgit-insert-patch-files patch))
91 (put-text-property start (point) 'patch-data patch)))
93 (defun create-stgit-buffer (dir)
94 "Create a buffer for showing StGit patches.
95 Argument DIR is the repository path."
96 (let ((buf (create-file-buffer (concat dir "*stgit*")))
97 (inhibit-read-only t))
98 (with-current-buffer buf
99 (setq default-directory dir)
101 (set (make-local-variable 'stgit-ewoc)
102 (ewoc-create #'stgit-patch-pp "Branch:\n\n" "--\n" t))
103 (setq buffer-read-only t))
106 (defmacro stgit-capture-output (name &rest body)
107 "Capture StGit output and, if there was any output, show it in a window
109 Returns nil if there was no output."
110 (declare (debug ([&or stringp null] body))
112 `(let ((output-buf (get-buffer-create ,(or name "*StGit output*")))
113 (stgit-dir default-directory)
114 (inhibit-read-only t))
115 (with-current-buffer output-buf
117 (setq default-directory stgit-dir)
118 (setq buffer-read-only t))
119 (let ((standard-output output-buf))
121 (with-current-buffer output-buf
122 (set-buffer-modified-p nil)
123 (setq buffer-read-only t)
124 (if (< (point-min) (point-max))
125 (display-buffer output-buf t)))))
127 (defun stgit-make-run-args (args)
128 "Return a copy of ARGS with its elements converted to strings."
130 ;; don't use (format "%s" ...) to limit type errors
131 (cond ((stringp x) x)
132 ((integerp x) (number-to-string x))
133 ((symbolp x) (symbol-name x))
135 (error "Bad element in stgit-make-run-args args: %S" x))))
138 (defun stgit-run-silent (&rest args)
139 (setq args (stgit-make-run-args args))
140 (apply 'call-process "stg" nil standard-output nil args))
142 (defun stgit-run (&rest args)
143 (setq args (stgit-make-run-args args))
144 (let ((msgcmd (mapconcat #'identity args " ")))
145 (message "Running stg %s..." msgcmd)
146 (apply 'call-process "stg" nil standard-output nil args)
147 (message "Running stg %s...done" msgcmd)))
149 (defun stgit-run-git (&rest args)
150 (setq args (stgit-make-run-args args))
151 (let ((msgcmd (mapconcat #'identity args " ")))
152 (message "Running git %s..." msgcmd)
153 (apply 'call-process "git" nil standard-output nil args)
154 (message "Running git %s...done" msgcmd)))
156 (defun stgit-run-git-silent (&rest args)
157 (setq args (stgit-make-run-args args))
158 (apply 'call-process "git" nil standard-output nil args))
160 (defun stgit-index-empty-p ()
161 "Returns non-nil if the index contains no changes from HEAD."
162 (zerop (stgit-run-git-silent "diff-index" "--cached" "--quiet" "HEAD")))
164 (defvar stgit-index-node)
165 (defvar stgit-worktree-node)
167 (defun stgit-refresh-index ()
168 (when stgit-index-node
169 (ewoc-invalidate (car stgit-index-node) (cdr stgit-index-node))))
171 (defun stgit-refresh-worktree ()
172 (when stgit-worktree-node
173 (ewoc-invalidate (car stgit-worktree-node) (cdr stgit-worktree-node))))
175 (defun stgit-run-series-insert-index (ewoc)
176 (setq index-node (cons ewoc (ewoc-enter-last ewoc
182 worktree-node (cons ewoc (ewoc-enter-last ewoc
189 (defun stgit-run-series (ewoc)
190 (setq stgit-index-node nil
191 stgit-worktree-node nil)
192 (let ((inserted-index (not stgit-show-worktree))
197 (let ((exit-status (stgit-run-silent "series" "--description" "--empty")))
198 (goto-char (point-min))
199 (if (not (zerop exit-status))
200 (cond ((looking-at "stg series: \\(.*\\)")
201 (setq inserted-index t)
202 (ewoc-set-hf ewoc (car (ewoc-get-hf ewoc))
203 (substitute-command-keys
204 "-- not initialized; run \\[stgit-init]")))
206 (error "Error running stg: %s"
210 "\\([0 ]\\)\\([>+-]\\)\\( \\)\\([^ ]+\\) *[|#] \\(.*\\)")
211 (error "Syntax error in output from stg series"))
212 (let* ((state-str (match-string 2))
213 (state (cond ((string= state-str ">") 'top)
214 ((string= state-str "+") 'applied)
215 ((string= state-str "-") 'unapplied)))
216 (name (intern (match-string 4)))
217 (desc (match-string 5))
218 (empty (string= (match-string 1) "0")))
219 (unless inserted-index
220 (when (or (eq stgit-show-worktree-mode 'top)
221 (and (eq stgit-show-worktree-mode 'center)
222 (eq state 'unapplied)))
223 (setq inserted-index t)
224 (stgit-run-series-insert-index ewoc)))
225 (setq all-patchsyms (cons name all-patchsyms))
226 (ewoc-enter-last ewoc
233 (unless inserted-index
234 (stgit-run-series-insert-index ewoc)))
235 (setq stgit-index-node index-node
236 stgit-worktree-node worktree-node
237 stgit-marked-patches (intersection stgit-marked-patches
240 (defun stgit-reload ()
241 "Update the contents of the StGit buffer."
243 (let ((inhibit-read-only t)
244 (curline (line-number-at-pos))
245 (curpatch (stgit-patch-name-at-point))
246 (curfile (stgit-patched-file-at-point)))
247 (ewoc-filter stgit-ewoc #'(lambda (x) nil))
248 (ewoc-set-hf stgit-ewoc
252 (stgit-run-silent "branch")
253 (buffer-substring (point-min) (1- (point-max))))
254 'face 'stgit-branch-name-face)
256 (if stgit-show-worktree
259 (substitute-command-keys "--\n\"\\[stgit-toggle-worktree]\"\
260 shows the working tree\n")
261 'face 'stgit-description-face)))
262 (stgit-run-series stgit-ewoc)
264 (stgit-goto-patch curpatch (and curfile (stgit-file-file curfile)))
265 (goto-line curline)))
266 (stgit-refresh-git-status))
269 "A user interface for the StGit patch maintenance tool."
272 (defface stgit-description-face
273 '((((background dark)) (:foreground "tan"))
274 (((background light)) (:foreground "dark red")))
275 "The face used for StGit descriptions"
278 (defface stgit-branch-name-face
280 "The face used for the StGit branch name"
283 (defface stgit-top-patch-face
284 '((((background dark)) (:weight bold :foreground "yellow"))
285 (((background light)) (:weight bold :foreground "purple"))
287 "The face used for the top patch names"
290 (defface stgit-applied-patch-face
291 '((((background dark)) (:foreground "light yellow"))
292 (((background light)) (:foreground "purple"))
294 "The face used for applied patch names"
297 (defface stgit-unapplied-patch-face
298 '((((background dark)) (:foreground "gray80"))
299 (((background light)) (:foreground "orchid"))
301 "The face used for unapplied patch names"
304 (defface stgit-modified-file-face
305 '((((class color) (background light)) (:foreground "purple"))
306 (((class color) (background dark)) (:foreground "salmon")))
307 "StGit mode face used for modified file status"
310 (defface stgit-unmerged-file-face
311 '((((class color) (background light)) (:foreground "red" :bold t))
312 (((class color) (background dark)) (:foreground "red" :bold t)))
313 "StGit mode face used for unmerged file status"
316 (defface stgit-unknown-file-face
317 '((((class color) (background light)) (:foreground "goldenrod" :bold t))
318 (((class color) (background dark)) (:foreground "goldenrod" :bold t)))
319 "StGit mode face used for unknown file status"
322 (defface stgit-ignored-file-face
323 '((((class color) (background light)) (:foreground "grey60"))
324 (((class color) (background dark)) (:foreground "grey40")))
325 "StGit mode face used for ignored files")
327 (defface stgit-file-permission-face
328 '((((class color) (background light)) (:foreground "green" :bold t))
329 (((class color) (background dark)) (:foreground "green" :bold t)))
330 "StGit mode face used for permission changes."
333 (defface stgit-index-work-tree-title-face
334 '((((supports :slant italic)) :slant italic)
336 "StGit mode face used for the \"Index\" and \"Work tree\" titles"
340 (defcustom stgit-find-copies-harder
342 "Try harder to find copied files when listing patches.
344 When not nil, runs git diff-tree with the --find-copies-harder
345 flag, which reduces performance."
349 (defconst stgit-file-status-code-strings
350 (mapcar (lambda (arg)
352 (propertize (cadr arg) 'face (car (cddr arg)))))
353 '((add "Added" stgit-modified-file-face)
354 (copy "Copied" stgit-modified-file-face)
355 (delete "Deleted" stgit-modified-file-face)
356 (modify "Modified" stgit-modified-file-face)
357 (rename "Renamed" stgit-modified-file-face)
358 (mode-change "Mode change" stgit-modified-file-face)
359 (unmerged "Unmerged" stgit-unmerged-file-face)
360 (unknown "Unknown" stgit-unknown-file-face)
361 (ignore "Ignored" stgit-ignored-file-face)))
362 "Alist of code symbols to description strings")
364 (defconst stgit-patch-status-face-alist
365 '((applied . stgit-applied-patch-face)
366 (top . stgit-top-patch-face)
367 (unapplied . stgit-unapplied-patch-face)
368 (index . stgit-index-work-tree-title-face)
369 (work . stgit-index-work-tree-title-face))
370 "Alist of face to use for a given patch status")
372 (defun stgit-file-status-code-as-string (file)
373 "Return stgit status code for FILE as a string"
374 (let* ((code (assq (stgit-file-status file)
375 stgit-file-status-code-strings))
376 (score (stgit-file-cr-score file)))
379 (if (and score (/= score 100))
380 (format "%s %s" (cdr code)
381 (propertize (format "%d%%" score)
382 'face 'stgit-description-face))
385 (defun stgit-file-status-code (str &optional score)
386 "Return stgit status code from git status string"
387 (let ((code (assoc str '(("A" . add)
396 (setq code (if code (cdr code) 'unknown))
397 (when (stringp score)
398 (if (> (length score) 0)
399 (setq score (string-to-number score))
401 (if score (cons code score) code)))
403 (defconst stgit-file-type-strings
406 (#o160 . "subproject"))
407 "Alist of names of file types")
409 (defun stgit-file-type-string (type)
410 "Return string describing file type TYPE (the high bits of file permission).
411 Cf. `stgit-file-type-strings' and `stgit-file-type-change-string'."
412 (let ((type-str (assoc type stgit-file-type-strings)))
413 (or (and type-str (cdr type-str))
414 (format "unknown type %o" type))))
416 (defun stgit-file-type-change-string (old-perm new-perm)
417 "Return string describing file type change from OLD-PERM to NEW-PERM.
418 Cf. `stgit-file-type-string'."
419 (let ((old-type (lsh old-perm -9))
420 (new-type (lsh new-perm -9)))
421 (cond ((= old-type new-type) "")
422 ((zerop new-type) "")
424 (if (= new-type #o100)
426 (format " (%s)" (stgit-file-type-string new-type))))
427 (t (format " (%s -> %s)"
428 (stgit-file-type-string old-type)
429 (stgit-file-type-string new-type))))))
431 (defun stgit-file-mode-change-string (old-perm new-perm)
432 "Return string describing file mode change from OLD-PERM to NEW-PERM.
433 Cf. `stgit-file-type-change-string'."
434 (setq old-perm (logand old-perm #o777)
435 new-perm (logand new-perm #o777))
436 (if (or (= old-perm new-perm)
440 (let* ((modified (logxor old-perm new-perm))
441 (not-x-modified (logand (logxor old-perm new-perm) #o666)))
442 (cond ((zerop modified) "")
443 ((and (zerop not-x-modified)
444 (or (and (eq #o111 (logand old-perm #o111))
445 (propertize "-x" 'face 'stgit-file-permission-face))
446 (and (eq #o111 (logand new-perm #o111))
447 (propertize "+x" 'face
448 'stgit-file-permission-face)))))
449 (t (concat (propertize (format "%o" old-perm)
450 'face 'stgit-file-permission-face)
452 'face 'stgit-description-face)
453 (propertize (format "%o" new-perm)
454 'face 'stgit-file-permission-face)))))))
456 (defstruct (stgit-file)
457 old-perm new-perm copy-or-rename cr-score cr-from cr-to status file)
459 (defun stgit-file-pp (file)
460 (let ((status (stgit-file-status file))
461 (name (if (stgit-file-copy-or-rename file)
462 (concat (stgit-file-cr-from file)
464 'face 'stgit-description-face)
465 (stgit-file-cr-to file))
466 (stgit-file-file file)))
467 (mode-change (stgit-file-mode-change-string
468 (stgit-file-old-perm file)
469 (stgit-file-new-perm file)))
471 (insert (format " %-12s%1s%s%s\n"
472 (stgit-file-status-code-as-string file)
475 (propertize (stgit-file-type-change-string
476 (stgit-file-old-perm file)
477 (stgit-file-new-perm file))
478 'face 'stgit-description-face)))
479 (add-text-properties start (point)
480 (list 'entry-type 'file
483 (defun stgit-find-copies-harder-diff-arg ()
484 "Return the flag to use with `git-diff' depending on the
485 `stgit-find-copies-harder' flag."
486 (if stgit-find-copies-harder "--find-copies-harder" "-C"))
488 (defun stgit-insert-ls-files (args file-flag)
489 (let ((start (point)))
490 (apply 'stgit-run-git
491 (append '("ls-files" "--exclude-standard" "-z") args))
493 (while (looking-at "\\([^\0]*\\)\0")
494 (let ((name-len (- (match-end 0) (match-beginning 0))))
495 (insert ":0 0 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 " file-flag "\0")
496 (forward-char name-len)))))
498 (defun stgit-insert-patch-files (patch)
499 "Expand (show modification of) the patch PATCH after the line
501 (let* ((patchsym (stgit-patch-name patch))
503 (args (list "-z" (stgit-find-copies-harder-diff-arg)))
504 (ewoc (ewoc-create #'stgit-file-pp nil nil t)))
505 (set-marker-insertion-type end t)
506 (setf (stgit-patch-files-ewoc patch) ewoc)
508 (apply 'stgit-run-git
509 (cond ((eq patchsym :work)
510 `("diff-files" "-0" ,@args))
511 ((eq patchsym :index)
512 `("diff-index" ,@args "--cached" "HEAD"))
514 `("diff-tree" ,@args "-r" ,(stgit-id patchsym)))))
516 (when (and (eq patchsym :work))
517 (when stgit-show-ignored
518 (stgit-insert-ls-files '("--ignored" "--others") "I"))
519 (when stgit-show-unknown
520 (stgit-insert-ls-files '("--others") "X"))
521 (sort-regexp-fields nil ":[^\0]*\0\\([^\0]*\\)\0" "\\1"
522 (point-min) (point-max)))
524 (goto-char (point-min))
525 (unless (or (eobp) (memq patchsym '(:work :index)))
527 (while (looking-at ":\\([0-7]+\\) \\([0-7]+\\) [0-9A-Fa-f]\\{40\\} [0-9A-Fa-f]\\{40\\} ")
528 (let ((old-perm (string-to-number (match-string 1) 8))
529 (new-perm (string-to-number (match-string 2) 8)))
530 (goto-char (match-end 0))
533 "\\([CR]\\)\\([0-9]*\\)\0\\([^\0]*\\)\0\\([^\0]*\\)\0")
534 (let* ((patch-status (stgit-patch-status patch))
535 (file-subexp (if (eq patch-status 'unapplied)
538 (file (match-string file-subexp)))
543 :cr-score (string-to-number (match-string 2))
544 :cr-from (match-string 3)
545 :cr-to (match-string 4)
546 :status (stgit-file-status-code
549 ((looking-at "\\([ABD-QS-Z]\\)\0\\([^\0]*\\)\0")
557 :status (stgit-file-status-code
559 :file (match-string 2))))))
560 (ewoc-enter-last ewoc file))
561 (goto-char (match-end 0))))
562 (unless (ewoc-nth ewoc 0)
565 (propertize "<no files>"
566 'face 'stgit-description-face)
570 (defun stgit-find-file (&optional other-window)
571 (let* ((file (or (stgit-patched-file-at-point)
572 (error "No file at point")))
573 (filename (expand-file-name (stgit-file-file file))))
574 (unless (file-exists-p filename)
575 (error "File does not exist"))
576 (funcall (if other-window 'find-file-other-window 'find-file)
578 (when (eq (stgit-file-status file) 'unmerged)
581 (defun stgit-select-patch ()
582 (let ((patchname (stgit-patch-name-at-point)))
583 (if (memq patchname stgit-expanded-patches)
584 (setq stgit-expanded-patches (delq patchname stgit-expanded-patches))
585 (setq stgit-expanded-patches (cons patchname stgit-expanded-patches)))
586 (ewoc-invalidate stgit-ewoc (ewoc-locate stgit-ewoc)))
587 (move-to-column (stgit-goal-column)))
589 (defun stgit-select ()
590 "With point on a patch, toggle showing files in the patch.
592 With point on a file, open the associated file. Opens the target
593 file for (applied) copies and renames."
595 (case (get-text-property (point) 'entry-type)
597 (stgit-select-patch))
601 (error "No patch or file on line"))))
603 (defun stgit-find-file-other-window ()
604 "Open file at point in other window"
608 (defun stgit-find-file-merge ()
609 "Open file at point and merge it using `smerge-ediff'."
615 "Hide the stgit buffer."
619 (defun stgit-git-status ()
620 "Show status using `git-status'."
622 (unless (fboundp 'git-status)
623 (error "The stgit-git-status command requires git-status"))
624 (let ((dir default-directory))
625 (save-selected-window
629 (defun stgit-goal-column ()
630 "Return goal column for the current line"
631 (case (get-text-property (point) 'entry-type)
636 (defun stgit-next-line (&optional arg)
637 "Move cursor vertically down ARG lines"
640 (move-to-column (stgit-goal-column)))
642 (defun stgit-previous-line (&optional arg)
643 "Move cursor vertically up ARG lines"
646 (move-to-column (stgit-goal-column)))
648 (defun stgit-next-patch (&optional arg)
649 "Move cursor down ARG patches."
651 (ewoc-goto-next stgit-ewoc (or arg 1))
652 (move-to-column goal-column))
654 (defun stgit-previous-patch (&optional arg)
655 "Move cursor up ARG patches."
657 (ewoc-goto-prev stgit-ewoc (or arg 1))
658 (move-to-column goal-column))
660 (defvar stgit-mode-hook nil
661 "Run after `stgit-mode' is setup.")
663 (defvar stgit-mode-map nil
664 "Keymap for StGit major mode.")
666 (unless stgit-mode-map
667 (let ((diff-map (make-keymap))
668 (toggle-map (make-keymap)))
669 (suppress-keymap diff-map)
670 (mapc (lambda (arg) (define-key diff-map (car arg) (cdr arg)))
671 '(("b" . stgit-diff-base)
672 ("c" . stgit-diff-combined)
673 ("m" . stgit-find-file-merge)
674 ("o" . stgit-diff-ours)
675 ("t" . stgit-diff-theirs)))
676 (suppress-keymap toggle-map)
677 (mapc (lambda (arg) (define-key toggle-map (car arg) (cdr arg)))
678 '(("t" . stgit-toggle-worktree)
679 ("i" . stgit-toggle-ignored)
680 ("u" . stgit-toggle-unknown)))
681 (setq stgit-mode-map (make-keymap))
682 (suppress-keymap stgit-mode-map)
683 (mapc (lambda (arg) (define-key stgit-mode-map (car arg) (cdr arg)))
686 ("\d" . stgit-unmark-up)
687 ("u" . stgit-unmark-down)
690 ("\C-p" . stgit-previous-line)
691 ("\C-n" . stgit-next-line)
692 ([up] . stgit-previous-line)
693 ([down] . stgit-next-line)
694 ("p" . stgit-previous-patch)
695 ("n" . stgit-next-patch)
696 ("\M-{" . stgit-previous-patch)
697 ("\M-}" . stgit-next-patch)
698 ("s" . stgit-git-status)
699 ("g" . stgit-reload-or-repair)
700 ("r" . stgit-refresh)
701 ("\C-c\C-r" . stgit-rename)
703 ("M" . stgit-move-patches)
706 ("\C-c\C-c" . stgit-commit)
707 ("\C-c\C-u" . stgit-uncommit)
708 ("U" . stgit-revert-file)
709 ("R" . stgit-resolve-file)
710 ("\r" . stgit-select)
711 ("o" . stgit-find-file-other-window)
712 ("i" . stgit-file-toggle-index)
713 (">" . stgit-push-next)
714 ("<" . stgit-pop-next)
715 ("P" . stgit-push-or-pop)
719 ([(control ?/)] . stgit-undo)
720 ("\C-_" . stgit-undo)
724 ("q" . stgit-quit)))))
727 "Major mode for interacting with StGit.
730 (kill-all-local-variables)
731 (buffer-disable-undo)
732 (setq mode-name "StGit"
733 major-mode 'stgit-mode
735 (use-local-map stgit-mode-map)
736 (set (make-local-variable 'list-buffers-directory) default-directory)
737 (set (make-local-variable 'stgit-marked-patches) nil)
738 (set (make-local-variable 'stgit-expanded-patches) (list :work :index))
739 (set (make-local-variable 'stgit-show-worktree) stgit-default-show-worktree)
740 (set (make-local-variable 'stgit-index-node) nil)
741 (set (make-local-variable 'stgit-worktree-node) nil)
742 (set-variable 'truncate-lines 't)
743 (add-hook 'after-save-hook 'stgit-update-saved-file)
744 (run-hooks 'stgit-mode-hook))
746 (defun stgit-update-saved-file ()
747 (let* ((file (expand-file-name buffer-file-name))
748 (dir (file-name-directory file))
749 (gitdir (condition-case nil (git-get-top-dir dir)
751 (buffer (and gitdir (stgit-find-buffer gitdir))))
753 (with-current-buffer buffer
754 (stgit-refresh-worktree)))))
756 (defun stgit-add-mark (patchsym)
757 "Mark the patch PATCHSYM."
758 (setq stgit-marked-patches (cons patchsym stgit-marked-patches)))
760 (defun stgit-remove-mark (patchsym)
761 "Unmark the patch PATCHSYM."
762 (setq stgit-marked-patches (delq patchsym stgit-marked-patches)))
764 (defun stgit-clear-marks ()
765 "Unmark all patches."
766 (setq stgit-marked-patches '()))
768 (defun stgit-patch-at-point (&optional cause-error)
769 (get-text-property (point) 'patch-data))
771 (defun stgit-patch-name-at-point (&optional cause-error only-patches)
772 "Return the patch name on the current line as a symbol.
773 If CAUSE-ERROR is not nil, signal an error if none found.
774 If ONLY-PATCHES is not nil, only allow real patches, and not
776 (let ((patch (stgit-patch-at-point)))
779 (memq (stgit-patch-status patch) '(work index))
782 (stgit-patch-name patch))
784 (error "No patch on this line")))))
786 (defun stgit-patched-file-at-point ()
787 (get-text-property (point) 'file-data))
789 (defun stgit-patches-marked-or-at-point ()
790 "Return the symbols of the marked patches, or the patch on the current line."
791 (if stgit-marked-patches
793 (let ((patch (stgit-patch-name-at-point)))
798 (defun stgit-goto-patch (patchsym &optional file)
799 "Move point to the line containing patch PATCHSYM.
800 If that patch cannot be found, do nothing.
802 If the patch was found and FILE is not nil, instead move to that
803 file's line. If FILE cannot be found, stay on the line of
805 (let ((node (ewoc-nth stgit-ewoc 0)))
806 (while (and node (not (eq (stgit-patch-name (ewoc-data node))
808 (setq node (ewoc-next stgit-ewoc node)))
809 (when (and node file)
810 (let* ((file-ewoc (stgit-patch-files-ewoc (ewoc-data node)))
811 (file-node (ewoc-nth file-ewoc 0)))
812 (while (and file-node (not (equal (stgit-file-file (ewoc-data file-node)) file)))
813 (setq file-node (ewoc-next file-ewoc file-node)))
815 (ewoc-goto-node file-ewoc file-node)
816 (move-to-column (stgit-goal-column))
819 (ewoc-goto-node stgit-ewoc node)
820 (move-to-column goal-column))))
825 (stgit-capture-output nil
830 "Mark the patch under point."
832 (let* ((node (ewoc-locate stgit-ewoc))
833 (patch (ewoc-data node))
834 (name (stgit-patch-name patch)))
835 (when (eq name :work)
836 (error "Cannot mark the work tree"))
837 (when (eq name :index)
838 (error "Cannot mark the index"))
839 (stgit-add-mark (stgit-patch-name patch))
840 (ewoc-invalidate stgit-ewoc node))
843 (defun stgit-unmark-up ()
844 "Remove mark from the patch on the previous line."
846 (stgit-previous-patch)
847 (let* ((node (ewoc-locate stgit-ewoc))
848 (patch (ewoc-data node)))
849 (stgit-remove-mark (stgit-patch-name patch))
850 (ewoc-invalidate stgit-ewoc node))
851 (move-to-column (stgit-goal-column)))
853 (defun stgit-unmark-down ()
854 "Remove mark from the patch on the current line."
856 (let* ((node (ewoc-locate stgit-ewoc))
857 (patch (ewoc-data node)))
858 (stgit-remove-mark (stgit-patch-name patch))
859 (ewoc-invalidate stgit-ewoc node))
862 (defun stgit-rename (name)
863 "Rename the patch under point to NAME."
865 (read-string "Patch name: "
866 (symbol-name (stgit-patch-name-at-point t t)))))
867 (let ((old-patchsym (stgit-patch-name-at-point t t)))
868 (stgit-capture-output nil
869 (stgit-run "rename" old-patchsym name))
870 (let ((name-sym (intern name)))
871 (when (memq old-patchsym stgit-expanded-patches)
872 (setq stgit-expanded-patches
873 (cons name-sym (delq old-patchsym stgit-expanded-patches))))
874 (when (memq old-patchsym stgit-marked-patches)
875 (setq stgit-marked-patches
876 (cons name-sym (delq old-patchsym stgit-marked-patches))))
878 (stgit-goto-patch name-sym))))
880 (defun stgit-reload-or-repair (repair)
881 "Update the contents of the StGit buffer (`stgit-reload').
883 With a prefix argument, repair the StGit metadata if the branch
884 was modified with git commands (`stgit-repair')."
890 (defun stgit-repair ()
893 (stgit-capture-output nil
894 (stgit-run "repair"))
897 (defun stgit-available-branches ()
898 "Returns a list of the available stg branches"
899 (let ((output (with-output-to-string
900 (stgit-run "branch" "--list")))
903 (while (string-match "^>?\\s-+s\\s-+\\(\\S-+\\)" output start)
904 (setq result (cons (match-string 1 output) result))
905 (setq start (match-end 0)))
908 (defun stgit-branch (branch)
909 "Switch to branch BRANCH."
910 (interactive (list (completing-read "Switch to branch: "
911 (stgit-available-branches))))
912 (stgit-capture-output nil (stgit-run "branch" "--" branch))
915 (defun stgit-commit (count)
916 "Run stg commit on COUNT commits.
917 Interactively, the prefix argument is used as COUNT.
918 A negative COUNT will uncommit instead."
921 (stgit-uncommit (- count))
922 (stgit-capture-output nil (stgit-run "commit" "-n" count))
925 (defun stgit-uncommit (count)
926 "Run stg uncommit on COUNT commits.
927 Interactively, the prefix argument is used as COUNT.
928 A negative COUNT will commit instead."
931 (stgit-commit (- count))
932 (stgit-capture-output nil (stgit-run "uncommit" "-n" count))
935 (defun stgit-revert-file ()
936 "Revert the file at point, which must be in the index or the
939 (let* ((patched-file (or (stgit-patched-file-at-point)
940 (error "No file on the current line")))
941 (patch-name (stgit-patch-name-at-point))
942 (file-status (stgit-file-status patched-file))
943 (rm-file (cond ((stgit-file-copy-or-rename patched-file)
944 (stgit-file-cr-to patched-file))
945 ((eq file-status 'add)
946 (stgit-file-file patched-file))))
947 (co-file (cond ((eq file-status 'rename)
948 (stgit-file-cr-from patched-file))
949 ((not (memq file-status '(copy add)))
950 (stgit-file-file patched-file)))))
952 (unless (memq patch-name '(:work :index))
953 (error "No index or working tree file on this line"))
955 (when (eq file-status 'ignore)
956 (error "Cannot revert ignored files"))
958 (when (eq file-status 'unknown)
959 (error "Cannot revert unknown files"))
961 (let ((nfiles (+ (if rm-file 1 0) (if co-file 1 0))))
962 (when (yes-or-no-p (format "Revert %d file%s? "
964 (if (= nfiles 1) "" "s")))
965 (stgit-capture-output nil
967 (stgit-run-git "rm" "-f" "-q" "--" rm-file))
969 (stgit-run-git "checkout" "HEAD" co-file)))
972 (defun stgit-resolve-file ()
973 "Resolve conflict in the file at point."
975 (let* ((patched-file (stgit-patched-file-at-point))
976 (patch (stgit-patch-at-point))
977 (patch-name (and patch (stgit-patch-name patch)))
978 (status (and patched-file (stgit-file-status patched-file))))
980 (unless (memq patch-name '(:work :index))
981 (error "No index or working tree file on this line"))
983 (unless (eq status 'unmerged)
984 (error "No conflict to resolve at the current line"))
986 (stgit-capture-output nil
987 (stgit-move-change-to-index (stgit-file-file patched-file)))
991 (defun stgit-push-next (npatches)
992 "Push the first unapplied patch.
993 With numeric prefix argument, push that many patches."
995 (stgit-capture-output nil (stgit-run "push" "-n" npatches))
997 (stgit-refresh-git-status))
999 (defun stgit-pop-next (npatches)
1000 "Pop the topmost applied patch.
1001 With numeric prefix argument, pop that many patches."
1003 (stgit-capture-output nil (stgit-run "pop" "-n" npatches))
1005 (stgit-refresh-git-status))
1007 (defun stgit-applied-at-point ()
1008 "Is the patch on the current line applied?"
1011 (looking-at "[>+]")))
1013 (defun stgit-push-or-pop ()
1014 "Push or pop the patch on the current line."
1016 (let ((patchsym (stgit-patch-name-at-point t))
1017 (applied (stgit-applied-at-point)))
1018 (stgit-capture-output nil
1019 (stgit-run (if applied "pop" "push") patchsym))
1022 (defun stgit-goto ()
1023 "Go to the patch on the current line."
1025 (let ((patchsym (stgit-patch-name-at-point t)))
1026 (stgit-capture-output nil
1027 (stgit-run "goto" patchsym))
1030 (defun stgit-id (patchsym)
1031 "Return the git commit id for PATCHSYM.
1032 If PATCHSYM is a keyword, returns PATCHSYM unmodified."
1033 (if (keywordp patchsym)
1035 (let ((result (with-output-to-string
1036 (stgit-run-silent "id" patchsym))))
1037 (unless (string-match "^\\([0-9A-Fa-f]\\{40\\}\\)$" result)
1038 (error "Cannot find commit id for %s" patchsym))
1039 (match-string 1 result))))
1041 (defun stgit-show-patch (unmerged-stage)
1042 "Show the patch on the current line.
1044 UNMERGED-STAGE is the argument to `git-diff' that that selects
1045 which stage to diff against in the case of unmerged files."
1046 (stgit-capture-output "*StGit patch*"
1047 (case (get-text-property (point) 'entry-type)
1049 (let* ((patched-file (stgit-patched-file-at-point))
1050 (patch-name (stgit-patch-name-at-point))
1051 (patch-id (let ((id (stgit-id patch-name)))
1052 (if (and (eq id :index)
1053 (eq (stgit-file-status patched-file)
1057 (args (append (and (stgit-file-cr-from patched-file)
1058 (list (stgit-find-copies-harder-diff-arg)))
1059 (cond ((eq patch-id :index)
1061 ((eq patch-id :work)
1062 (list unmerged-stage))
1064 (list (concat patch-id "^") patch-id)))
1066 (if (stgit-file-copy-or-rename patched-file)
1067 (list (stgit-file-cr-from patched-file)
1068 (stgit-file-cr-to patched-file))
1069 (list (stgit-file-file patched-file))))))
1070 (apply 'stgit-run-git "diff" args)))
1072 (let* ((patch-name (stgit-patch-name-at-point))
1073 (patch-id (stgit-id patch-name)))
1074 (if (or (eq patch-id :index) (eq patch-id :work))
1075 (apply 'stgit-run-git "diff"
1076 (stgit-find-copies-harder-diff-arg)
1077 (if (eq patch-id :index)
1079 (list unmerged-stage)))
1080 (stgit-run "show" "-O" "--patch-with-stat" "-O" "-M"
1081 (stgit-patch-name-at-point)))))
1083 (error "No patch or file at point")))
1084 (with-current-buffer standard-output
1085 (goto-char (point-min))
1088 (defun stgit-diff ()
1089 "Show the patch on the current line."
1091 (stgit-show-patch "--ours"))
1093 (defun stgit-diff-ours ()
1094 "Show the patch on the current line.
1096 For unmerged files, diff against our branch."
1098 (stgit-show-patch "--ours"))
1100 (defun stgit-diff-theirs ()
1101 "Show the patch on the current line.
1103 For unmerged files, diff against their branch."
1105 (stgit-show-patch "--theirs"))
1107 (defun stgit-diff-base ()
1108 "Show the patch on the current line.
1110 For unmerged files, diff against the base version."
1112 (stgit-show-patch "--base"))
1114 (defun stgit-diff-combined ()
1115 "Show the patch on the current line.
1117 For unmerged files, show a combined diff."
1119 (stgit-show-patch "--cc"))
1121 (defun stgit-move-change-to-index (file)
1122 "Copies the workspace state of FILE to index, using git add or git rm"
1123 (let ((op (if (or (file-exists-p file) (file-symlink-p file))
1124 '("add") '("rm" "-q"))))
1125 (stgit-capture-output "*git output*"
1126 (apply 'stgit-run-git (append op '("--") (list file))))))
1128 (defun stgit-remove-change-from-index (file)
1129 "Unstages the change in FILE from the index"
1130 (stgit-capture-output "*git output*"
1131 (stgit-run-git "reset" "-q" "--" file)))
1133 (defun stgit-file-toggle-index ()
1134 "Move modified file in or out of the index.
1136 Leaves the point where it is, but moves the mark to where the
1137 file ended up. You can then jump to the file with \
1138 \\[exchange-point-and-mark]."
1140 (let ((patched-file (stgit-patched-file-at-point)))
1141 (unless patched-file
1142 (error "No file on the current line"))
1143 (when (eq (stgit-file-status patched-file) 'unmerged)
1144 (error (substitute-command-keys "Use \\[stgit-resolve-file] to move an unmerged file to the index")))
1145 (when (eq (stgit-file-status patched-file) 'ignore)
1146 (error "You cannot add ignored files to the index"))
1147 (let* ((patch (stgit-patch-at-point))
1148 (patch-name (stgit-patch-name patch))
1152 ;; find the next file in the patch, or the previous one if this
1153 ;; was the last file
1154 (and (zerop (forward-line 1))
1155 (let ((f (stgit-patched-file-at-point)))
1156 (and f (setq next-file (stgit-file-file f)))))
1157 (goto-char old-point)
1159 (and (zerop (forward-line -1))
1160 (let ((f (stgit-patched-file-at-point)))
1161 (and f (setq next-file (stgit-file-file f)))))
1162 (goto-char old-point))
1164 (cond ((eq patch-name :work)
1165 (stgit-move-change-to-index (stgit-file-file patched-file)))
1166 ((eq patch-name :index)
1167 (stgit-remove-change-from-index (stgit-file-file patched-file)))
1169 (error "Can only move files in the working tree to index")))
1170 (stgit-refresh-worktree)
1171 (stgit-refresh-index)
1172 (stgit-goto-patch (if (eq patch-name :index) :work :index)
1173 (stgit-file-file patched-file))
1175 (stgit-goto-patch patch-name next-file))))
1177 (defun stgit-edit ()
1178 "Edit the patch on the current line."
1180 (let ((patchsym (stgit-patch-name-at-point t t))
1181 (edit-buf (get-buffer-create "*StGit edit*"))
1182 (dir default-directory))
1183 (log-edit 'stgit-confirm-edit t nil edit-buf)
1184 (set (make-local-variable 'stgit-edit-patchsym) patchsym)
1185 (setq default-directory dir)
1186 (let ((standard-output edit-buf))
1187 (stgit-run-silent "edit" "--save-template=-" patchsym))))
1189 (defun stgit-confirm-edit ()
1191 (let ((file (make-temp-file "stgit-edit-")))
1192 (write-region (point-min) (point-max) file)
1193 (stgit-capture-output nil
1194 (stgit-run "edit" "-f" file stgit-edit-patchsym))
1195 (with-current-buffer log-edit-parent-buffer
1198 (defun stgit-new (add-sign)
1199 "Create a new patch.
1200 With a prefix argument, include a \"Signed-off-by:\" line at the
1203 (let ((edit-buf (get-buffer-create "*StGit edit*"))
1204 (dir default-directory))
1205 (log-edit 'stgit-confirm-new t nil edit-buf)
1206 (setq default-directory dir)
1209 (let ((standard-output (current-buffer)))
1210 (stgit-run-silent "new" "--sign" "--save-template=-"))))))
1212 (defun stgit-confirm-new ()
1214 (let ((file (make-temp-file "stgit-edit-")))
1215 (write-region (point-min) (point-max) file)
1216 (stgit-capture-output nil
1217 (stgit-run "new" "-f" file))
1218 (with-current-buffer log-edit-parent-buffer
1221 (defun stgit-create-patch-name (description)
1222 "Create a patch name from a long description"
1224 (while (> (length description) 0)
1225 (cond ((string-match "\\`[a-zA-Z_-]+" description)
1226 (setq patch (downcase (concat patch
1227 (match-string 0 description))))
1228 (setq description (substring description (match-end 0))))
1229 ((string-match "\\` +" description)
1230 (setq patch (concat patch "-"))
1231 (setq description (substring description (match-end 0))))
1232 ((string-match "\\`[^a-zA-Z_-]+" description)
1233 (setq description (substring description (match-end 0))))))
1234 (cond ((= (length patch) 0)
1236 ((> (length patch) 20)
1237 (substring patch 0 20))
1240 (defun stgit-delete (patchsyms &optional spill-p)
1241 "Delete the patches in PATCHSYMS.
1242 Interactively, delete the marked patches, or the patch at point.
1244 With a prefix argument, or SPILL-P, spill the patch contents to
1245 the work tree and index."
1246 (interactive (list (stgit-patches-marked-or-at-point)
1247 current-prefix-arg))
1249 (error "No patches to delete"))
1250 (when (memq :index patchsyms)
1251 (error "Cannot delete the index"))
1252 (when (memq :work patchsyms)
1253 (error "Cannot delete the work tree"))
1255 (let ((npatches (length patchsyms)))
1256 (when (yes-or-no-p (format "Really delete %d patch%s%s? "
1258 (if (= 1 npatches) "" "es")
1260 " (spilling contents to index)"
1262 (let ((args (if spill-p
1263 (cons "--spill" patchsyms)
1265 (stgit-capture-output nil
1266 (apply 'stgit-run "delete" args))
1269 (defun stgit-move-patches-target ()
1270 "Return the patchsym indicating a target patch for
1271 `stgit-move-patches'.
1273 This is either the patch at point, or one of :top and :bottom, if
1274 the point is after or before the applied patches."
1276 (let ((patchsym (stgit-patch-name-at-point)))
1277 (cond (patchsym patchsym)
1278 ((save-excursion (re-search-backward "^>" nil t)) :top)
1281 (defun stgit-sort-patches (patchsyms)
1282 "Returns the list of patches in PATCHSYMS sorted according to
1283 their position in the patch series, bottommost first.
1285 PATCHSYMS may not contain duplicate entries."
1286 (let (sorted-patchsyms
1287 (series (with-output-to-string
1288 (with-current-buffer standard-output
1289 (stgit-run-silent "series" "--noprefix"))))
1291 (while (string-match "^\\(.+\\)" series start)
1292 (let ((patchsym (intern (match-string 1 series))))
1293 (when (memq patchsym patchsyms)
1294 (setq sorted-patchsyms (cons patchsym sorted-patchsyms))))
1295 (setq start (match-end 0)))
1296 (setq sorted-patchsyms (nreverse sorted-patchsyms))
1298 (unless (= (length patchsyms) (length sorted-patchsyms))
1299 (error "Internal error"))
1303 (defun stgit-move-patches (patchsyms target-patch)
1304 "Move the patches in PATCHSYMS to below TARGET-PATCH.
1305 If TARGET-PATCH is :bottom or :top, move the patches to the
1306 bottom or top of the stack, respectively.
1308 Interactively, move the marked patches to where the point is."
1309 (interactive (list stgit-marked-patches
1310 (stgit-move-patches-target)))
1312 (error "Need at least one patch to move"))
1314 (unless target-patch
1315 (error "Point not at a patch"))
1317 (if (eq target-patch :top)
1318 (stgit-capture-output nil
1319 (apply 'stgit-run "float" patchsyms))
1321 ;; need to have patchsyms sorted by position in the stack
1322 (let ((sorted-patchsyms (stgit-sort-patches patchsyms)))
1323 (while sorted-patchsyms
1324 (setq sorted-patchsyms
1325 (and (stgit-capture-output nil
1326 (if (eq target-patch :bottom)
1327 (stgit-run "sink" "--" (car sorted-patchsyms))
1328 (stgit-run "sink" "--to" target-patch "--"
1329 (car sorted-patchsyms))))
1330 (cdr sorted-patchsyms))))))
1333 (defun stgit-squash (patchsyms)
1334 "Squash the patches in PATCHSYMS.
1335 Interactively, squash the marked patches.
1337 Unless there are any conflicts, the patches will be merged into
1338 one patch, which will occupy the same spot in the series as the
1339 deepest patch had before the squash."
1340 (interactive (list stgit-marked-patches))
1341 (when (< (length patchsyms) 2)
1342 (error "Need at least two patches to squash"))
1343 (let ((stgit-buffer (current-buffer))
1344 (edit-buf (get-buffer-create "*StGit edit*"))
1345 (dir default-directory)
1346 (sorted-patchsyms (stgit-sort-patches patchsyms)))
1347 (log-edit 'stgit-confirm-squash t nil edit-buf)
1348 (set (make-local-variable 'stgit-patchsyms) sorted-patchsyms)
1349 (setq default-directory dir)
1350 (let ((result (let ((standard-output edit-buf))
1351 (apply 'stgit-run-silent "squash"
1352 "--save-template=-" sorted-patchsyms))))
1354 ;; stg squash may have reordered the patches or caused conflicts
1355 (with-current-buffer stgit-buffer
1358 (unless (eq 0 result)
1360 (rename-buffer "*StGit error*")
1361 (resize-temp-buffer-window)
1362 (switch-to-buffer-other-window stgit-buffer)
1363 (error "stg squash failed")))))
1365 (defun stgit-confirm-squash ()
1367 (let ((file (make-temp-file "stgit-edit-")))
1368 (write-region (point-min) (point-max) file)
1369 (stgit-capture-output nil
1370 (apply 'stgit-run "squash" "-f" file stgit-patchsyms))
1371 (with-current-buffer log-edit-parent-buffer
1373 ;; Go to first marked patch and stay there
1374 (goto-char (point-min))
1375 (re-search-forward (concat "^[>+-]\\*") nil t)
1376 (move-to-column goal-column)
1377 (let ((pos (point)))
1381 (defun stgit-help ()
1382 "Display help for the StGit mode."
1384 (describe-function 'stgit-mode))
1386 (defun stgit-undo (&optional arg)
1388 With prefix argument, run it with the --hard flag."
1390 (stgit-capture-output nil
1392 (stgit-run "undo" "--hard")
1393 (stgit-run "undo")))
1396 (defun stgit-refresh (&optional arg)
1398 If the index contains any changes, only refresh from index.
1400 With prefix argument, refresh the marked patch or the patch under point."
1402 (let ((patchargs (if arg
1403 (let ((patches (stgit-patches-marked-or-at-point)))
1404 (cond ((null patches)
1405 (error "No patch to update"))
1406 ((> (length patches) 1)
1407 (error "Too many patches selected"))
1409 (cons "-p" patches))))
1411 (unless (stgit-index-empty-p)
1412 (setq patchargs (cons "--index" patchargs)))
1413 (stgit-capture-output nil
1414 (apply 'stgit-run "refresh" patchargs))
1415 (stgit-refresh-git-status))
1418 (defcustom stgit-show-worktree-mode 'center
1419 "This variable controls where the \"Index\" and \"Work tree\"
1420 will be shown on in the buffer.
1422 It can be set to 'top (above all patches), 'center (show between
1423 applied and unapplied patches), and 'bottom (below all patches).
1425 See also `stgit-show-worktree'."
1426 :type '(radio (const :tag "above all patches (top)" top)
1427 (const :tag "between applied and unapplied patches (center)"
1429 (const :tag "below all patches (bottom)" bottom))
1432 (defcustom stgit-default-show-worktree
1434 "Set to non-nil to by default show the working tree in a new stgit buffer.
1436 This value is used as the default value for `stgit-show-worktree'."
1440 (defvar stgit-show-worktree nil
1441 "If nil, inhibit showing work tree and index in the stgit buffer.
1443 See also `stgit-show-worktree-mode'.")
1445 (defvar stgit-show-ignored nil
1446 "If nil, inhibit showing files ignored by git.")
1448 (defvar stgit-show-unknown nil
1449 "If nil, inhibit showing files not registered with git.")
1451 (defun stgit-toggle-worktree (&optional arg)
1452 "Toggle the visibility of the work tree.
1453 With arg, show the work tree if arg is positive.
1455 Its initial setting is controlled by `stgit-default-show-worktree'.
1457 `stgit-show-worktree-mode' controls where on screen the index and
1458 work tree will show up."
1460 (setq stgit-show-worktree
1463 (not stgit-show-worktree)))
1466 (defun stgit-toggle-ignored (&optional arg)
1467 "Toggle the visibility of files ignored by git in the work
1468 tree. With ARG, show these files if ARG is positive.
1470 Use \\[stgit-toggle-worktree] to show the work tree."
1472 (setq stgit-show-ignored
1475 (not stgit-show-ignored)))
1478 (defun stgit-toggle-unknown (&optional arg)
1479 "Toggle the visibility of files not registered with git in the
1480 work tree. With ARG, show these files if ARG is positive.
1482 Use \\[stgit-toggle-worktree] to show the work tree."
1484 (setq stgit-show-unknown
1487 (not stgit-show-unknown)))