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)
84 'syntax-table (string-to-syntax "w")))
86 (if (stgit-patch-empty patch) "(empty) " "")
87 (propertize (or (stgit-patch-desc patch) "")
88 'face 'stgit-description-face)))
90 (put-text-property start (point) 'entry-type 'patch)
91 (when (memq name stgit-expanded-patches)
92 (stgit-insert-patch-files patch))
93 (put-text-property start (point) 'patch-data patch)))
95 (defun create-stgit-buffer (dir)
96 "Create a buffer for showing StGit patches.
97 Argument DIR is the repository path."
98 (let ((buf (create-file-buffer (concat dir "*stgit*")))
99 (inhibit-read-only t))
100 (with-current-buffer buf
101 (setq default-directory dir)
103 (set (make-local-variable 'stgit-ewoc)
104 (ewoc-create #'stgit-patch-pp "Branch:\n\n" "--\n" t))
105 (setq buffer-read-only t))
108 (defmacro stgit-capture-output (name &rest body)
109 "Capture StGit output and, if there was any output, show it in a window
111 Returns nil if there was no output."
112 (declare (debug ([&or stringp null] body))
114 `(let ((output-buf (get-buffer-create ,(or name "*StGit output*")))
115 (stgit-dir default-directory)
116 (inhibit-read-only t))
117 (with-current-buffer output-buf
119 (setq default-directory stgit-dir)
120 (setq buffer-read-only t))
121 (let ((standard-output output-buf))
123 (with-current-buffer output-buf
124 (set-buffer-modified-p nil)
125 (setq buffer-read-only t)
126 (if (< (point-min) (point-max))
127 (display-buffer output-buf t)))))
129 (defun stgit-make-run-args (args)
130 "Return a copy of ARGS with its elements converted to strings."
132 ;; don't use (format "%s" ...) to limit type errors
133 (cond ((stringp x) x)
134 ((integerp x) (number-to-string x))
135 ((symbolp x) (symbol-name x))
137 (error "Bad element in stgit-make-run-args args: %S" x))))
140 (defun stgit-run-silent (&rest args)
141 (setq args (stgit-make-run-args args))
142 (apply 'call-process "stg" nil standard-output nil args))
144 (defun stgit-run (&rest args)
145 (setq args (stgit-make-run-args args))
146 (let ((msgcmd (mapconcat #'identity args " ")))
147 (message "Running stg %s..." msgcmd)
148 (apply 'call-process "stg" nil standard-output nil args)
149 (message "Running stg %s...done" msgcmd)))
151 (defun stgit-run-git (&rest args)
152 (setq args (stgit-make-run-args args))
153 (let ((msgcmd (mapconcat #'identity args " ")))
154 (message "Running git %s..." msgcmd)
155 (apply 'call-process "git" nil standard-output nil args)
156 (message "Running git %s...done" msgcmd)))
158 (defun stgit-run-git-silent (&rest args)
159 (setq args (stgit-make-run-args args))
160 (apply 'call-process "git" nil standard-output nil args))
162 (defun stgit-index-empty-p ()
163 "Returns non-nil if the index contains no changes from HEAD."
164 (zerop (stgit-run-git-silent "diff-index" "--cached" "--quiet" "HEAD")))
166 (defvar stgit-index-node)
167 (defvar stgit-worktree-node)
169 (defun stgit-refresh-index ()
170 (when stgit-index-node
171 (ewoc-invalidate (car stgit-index-node) (cdr stgit-index-node))))
173 (defun stgit-refresh-worktree ()
174 (when stgit-worktree-node
175 (ewoc-invalidate (car stgit-worktree-node) (cdr stgit-worktree-node))))
177 (defun stgit-run-series-insert-index (ewoc)
178 (setq index-node (cons ewoc (ewoc-enter-last ewoc
184 worktree-node (cons ewoc (ewoc-enter-last ewoc
191 (defun stgit-run-series (ewoc)
192 (setq stgit-index-node nil
193 stgit-worktree-node nil)
194 (let ((inserted-index (not stgit-show-worktree))
199 (let ((exit-status (stgit-run-silent "series" "--description" "--empty")))
200 (goto-char (point-min))
201 (if (not (zerop exit-status))
202 (cond ((looking-at "stg series: \\(.*\\)")
203 (setq inserted-index t)
204 (ewoc-set-hf ewoc (car (ewoc-get-hf ewoc))
205 (substitute-command-keys
206 "-- not initialized; run \\[stgit-init]")))
208 (error "Error running stg: %s"
212 "\\([0 ]\\)\\([>+-]\\)\\( \\)\\([^ ]+\\) *[|#] \\(.*\\)")
213 (error "Syntax error in output from stg series"))
214 (let* ((state-str (match-string 2))
215 (state (cond ((string= state-str ">") 'top)
216 ((string= state-str "+") 'applied)
217 ((string= state-str "-") 'unapplied)))
218 (name (intern (match-string 4)))
219 (desc (match-string 5))
220 (empty (string= (match-string 1) "0")))
221 (unless inserted-index
222 (when (or (eq stgit-show-worktree-mode 'top)
223 (and (eq stgit-show-worktree-mode 'center)
224 (eq state 'unapplied)))
225 (setq inserted-index t)
226 (stgit-run-series-insert-index ewoc)))
227 (setq all-patchsyms (cons name all-patchsyms))
228 (ewoc-enter-last ewoc
235 (unless inserted-index
236 (stgit-run-series-insert-index ewoc)))
237 (setq stgit-index-node index-node
238 stgit-worktree-node worktree-node
239 stgit-marked-patches (intersection stgit-marked-patches
242 (defun stgit-reload ()
243 "Update the contents of the StGit buffer."
245 (let ((inhibit-read-only t)
246 (curline (line-number-at-pos))
247 (curpatch (stgit-patch-name-at-point))
248 (curfile (stgit-patched-file-at-point)))
249 (ewoc-filter stgit-ewoc #'(lambda (x) nil))
250 (ewoc-set-hf stgit-ewoc
254 (stgit-run-silent "branch")
255 (buffer-substring (point-min) (1- (point-max))))
256 'face 'stgit-branch-name-face)
258 (if stgit-show-worktree
261 (substitute-command-keys "--\n\"\\[stgit-toggle-worktree]\"\
262 shows the working tree\n")
263 'face 'stgit-description-face)))
264 (stgit-run-series stgit-ewoc)
266 (stgit-goto-patch curpatch (and curfile (stgit-file-file curfile)))
267 (goto-line curline)))
268 (stgit-refresh-git-status))
271 "A user interface for the StGit patch maintenance tool."
274 (defface stgit-description-face
275 '((((background dark)) (:foreground "tan"))
276 (((background light)) (:foreground "dark red")))
277 "The face used for StGit descriptions"
280 (defface stgit-branch-name-face
282 "The face used for the StGit branch name"
285 (defface stgit-top-patch-face
286 '((((background dark)) (:weight bold :foreground "yellow"))
287 (((background light)) (:weight bold :foreground "purple"))
289 "The face used for the top patch names"
292 (defface stgit-applied-patch-face
293 '((((background dark)) (:foreground "light yellow"))
294 (((background light)) (:foreground "purple"))
296 "The face used for applied patch names"
299 (defface stgit-unapplied-patch-face
300 '((((background dark)) (:foreground "gray80"))
301 (((background light)) (:foreground "orchid"))
303 "The face used for unapplied patch names"
306 (defface stgit-modified-file-face
307 '((((class color) (background light)) (:foreground "purple"))
308 (((class color) (background dark)) (:foreground "salmon")))
309 "StGit mode face used for modified file status"
312 (defface stgit-unmerged-file-face
313 '((((class color) (background light)) (:foreground "red" :bold t))
314 (((class color) (background dark)) (:foreground "red" :bold t)))
315 "StGit mode face used for unmerged file status"
318 (defface stgit-unknown-file-face
319 '((((class color) (background light)) (:foreground "goldenrod" :bold t))
320 (((class color) (background dark)) (:foreground "goldenrod" :bold t)))
321 "StGit mode face used for unknown file status"
324 (defface stgit-ignored-file-face
325 '((((class color) (background light)) (:foreground "grey60"))
326 (((class color) (background dark)) (:foreground "grey40")))
327 "StGit mode face used for ignored files")
329 (defface stgit-file-permission-face
330 '((((class color) (background light)) (:foreground "green" :bold t))
331 (((class color) (background dark)) (:foreground "green" :bold t)))
332 "StGit mode face used for permission changes."
335 (defface stgit-index-work-tree-title-face
336 '((((supports :slant italic)) :slant italic)
338 "StGit mode face used for the \"Index\" and \"Work tree\" titles"
342 (defcustom stgit-find-copies-harder
344 "Try harder to find copied files when listing patches.
346 When not nil, runs git diff-tree with the --find-copies-harder
347 flag, which reduces performance."
351 (defconst stgit-file-status-code-strings
352 (mapcar (lambda (arg)
354 (propertize (cadr arg) 'face (car (cddr arg)))))
355 '((add "Added" stgit-modified-file-face)
356 (copy "Copied" stgit-modified-file-face)
357 (delete "Deleted" stgit-modified-file-face)
358 (modify "Modified" stgit-modified-file-face)
359 (rename "Renamed" stgit-modified-file-face)
360 (mode-change "Mode change" stgit-modified-file-face)
361 (unmerged "Unmerged" stgit-unmerged-file-face)
362 (unknown "Unknown" stgit-unknown-file-face)
363 (ignore "Ignored" stgit-ignored-file-face)))
364 "Alist of code symbols to description strings")
366 (defconst stgit-patch-status-face-alist
367 '((applied . stgit-applied-patch-face)
368 (top . stgit-top-patch-face)
369 (unapplied . stgit-unapplied-patch-face)
370 (index . stgit-index-work-tree-title-face)
371 (work . stgit-index-work-tree-title-face))
372 "Alist of face to use for a given patch status")
374 (defun stgit-file-status-code-as-string (file)
375 "Return stgit status code for FILE as a string"
376 (let* ((code (assq (stgit-file-status file)
377 stgit-file-status-code-strings))
378 (score (stgit-file-cr-score file)))
381 (if (and score (/= score 100))
382 (format "%s %s" (cdr code)
383 (propertize (format "%d%%" score)
384 'face 'stgit-description-face))
387 (defun stgit-file-status-code (str &optional score)
388 "Return stgit status code from git status string"
389 (let ((code (assoc str '(("A" . add)
398 (setq code (if code (cdr code) 'unknown))
399 (when (stringp score)
400 (if (> (length score) 0)
401 (setq score (string-to-number score))
403 (if score (cons code score) code)))
405 (defconst stgit-file-type-strings
408 (#o160 . "subproject"))
409 "Alist of names of file types")
411 (defun stgit-file-type-string (type)
412 "Return string describing file type TYPE (the high bits of file permission).
413 Cf. `stgit-file-type-strings' and `stgit-file-type-change-string'."
414 (let ((type-str (assoc type stgit-file-type-strings)))
415 (or (and type-str (cdr type-str))
416 (format "unknown type %o" type))))
418 (defun stgit-file-type-change-string (old-perm new-perm)
419 "Return string describing file type change from OLD-PERM to NEW-PERM.
420 Cf. `stgit-file-type-string'."
421 (let ((old-type (lsh old-perm -9))
422 (new-type (lsh new-perm -9)))
423 (cond ((= old-type new-type) "")
424 ((zerop new-type) "")
426 (if (= new-type #o100)
428 (format " (%s)" (stgit-file-type-string new-type))))
429 (t (format " (%s -> %s)"
430 (stgit-file-type-string old-type)
431 (stgit-file-type-string new-type))))))
433 (defun stgit-file-mode-change-string (old-perm new-perm)
434 "Return string describing file mode change from OLD-PERM to NEW-PERM.
435 Cf. `stgit-file-type-change-string'."
436 (setq old-perm (logand old-perm #o777)
437 new-perm (logand new-perm #o777))
438 (if (or (= old-perm new-perm)
442 (let* ((modified (logxor old-perm new-perm))
443 (not-x-modified (logand (logxor old-perm new-perm) #o666)))
444 (cond ((zerop modified) "")
445 ((and (zerop not-x-modified)
446 (or (and (eq #o111 (logand old-perm #o111))
447 (propertize "-x" 'face 'stgit-file-permission-face))
448 (and (eq #o111 (logand new-perm #o111))
449 (propertize "+x" 'face
450 'stgit-file-permission-face)))))
451 (t (concat (propertize (format "%o" old-perm)
452 'face 'stgit-file-permission-face)
454 'face 'stgit-description-face)
455 (propertize (format "%o" new-perm)
456 'face 'stgit-file-permission-face)))))))
458 (defstruct (stgit-file)
459 old-perm new-perm copy-or-rename cr-score cr-from cr-to status file)
461 (defun stgit-file-pp (file)
462 (let ((status (stgit-file-status file))
463 (name (if (stgit-file-copy-or-rename file)
464 (concat (stgit-file-cr-from file)
466 'face 'stgit-description-face)
467 (stgit-file-cr-to file))
468 (stgit-file-file file)))
469 (mode-change (stgit-file-mode-change-string
470 (stgit-file-old-perm file)
471 (stgit-file-new-perm file)))
473 (insert (format " %-12s%1s%s%s\n"
474 (stgit-file-status-code-as-string file)
477 (propertize (stgit-file-type-change-string
478 (stgit-file-old-perm file)
479 (stgit-file-new-perm file))
480 'face 'stgit-description-face)))
481 (add-text-properties start (point)
482 (list 'entry-type 'file
485 (defun stgit-find-copies-harder-diff-arg ()
486 "Return the flag to use with `git-diff' depending on the
487 `stgit-find-copies-harder' flag."
488 (if stgit-find-copies-harder "--find-copies-harder" "-C"))
490 (defun stgit-insert-ls-files (args file-flag)
491 (let ((start (point)))
492 (apply 'stgit-run-git
493 (append '("ls-files" "--exclude-standard" "-z") args))
495 (while (looking-at "\\([^\0]*\\)\0")
496 (let ((name-len (- (match-end 0) (match-beginning 0))))
497 (insert ":0 0 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 " file-flag "\0")
498 (forward-char name-len)))))
500 (defun stgit-insert-patch-files (patch)
501 "Expand (show modification of) the patch PATCH after the line
503 (let* ((patchsym (stgit-patch-name patch))
505 (args (list "-z" (stgit-find-copies-harder-diff-arg)))
506 (ewoc (ewoc-create #'stgit-file-pp nil nil t)))
507 (set-marker-insertion-type end t)
508 (setf (stgit-patch-files-ewoc patch) ewoc)
510 (apply 'stgit-run-git
511 (cond ((eq patchsym :work)
512 `("diff-files" "-0" ,@args))
513 ((eq patchsym :index)
514 `("diff-index" ,@args "--cached" "HEAD"))
516 `("diff-tree" ,@args "-r" ,(stgit-id patchsym)))))
518 (when (and (eq patchsym :work))
519 (when stgit-show-ignored
520 (stgit-insert-ls-files '("--ignored" "--others") "I"))
521 (when stgit-show-unknown
522 (stgit-insert-ls-files '("--others") "X"))
523 (sort-regexp-fields nil ":[^\0]*\0\\([^\0]*\\)\0" "\\1"
524 (point-min) (point-max)))
526 (goto-char (point-min))
527 (unless (or (eobp) (memq patchsym '(:work :index)))
529 (while (looking-at ":\\([0-7]+\\) \\([0-7]+\\) [0-9A-Fa-f]\\{40\\} [0-9A-Fa-f]\\{40\\} ")
530 (let ((old-perm (string-to-number (match-string 1) 8))
531 (new-perm (string-to-number (match-string 2) 8)))
532 (goto-char (match-end 0))
535 "\\([CR]\\)\\([0-9]*\\)\0\\([^\0]*\\)\0\\([^\0]*\\)\0")
536 (let* ((patch-status (stgit-patch-status patch))
537 (file-subexp (if (eq patch-status 'unapplied)
540 (file (match-string file-subexp)))
545 :cr-score (string-to-number (match-string 2))
546 :cr-from (match-string 3)
547 :cr-to (match-string 4)
548 :status (stgit-file-status-code
551 ((looking-at "\\([ABD-QS-Z]\\)\0\\([^\0]*\\)\0")
559 :status (stgit-file-status-code
561 :file (match-string 2))))))
562 (ewoc-enter-last ewoc file))
563 (goto-char (match-end 0))))
564 (unless (ewoc-nth ewoc 0)
567 (propertize "<no files>"
568 'face 'stgit-description-face)
572 (defun stgit-find-file (&optional other-window)
573 (let* ((file (or (stgit-patched-file-at-point)
574 (error "No file at point")))
575 (filename (expand-file-name (stgit-file-file file))))
576 (unless (file-exists-p filename)
577 (error "File does not exist"))
578 (funcall (if other-window 'find-file-other-window 'find-file)
580 (when (eq (stgit-file-status file) 'unmerged)
583 (defun stgit-select-patch ()
584 (let ((patchname (stgit-patch-name-at-point)))
585 (if (memq patchname stgit-expanded-patches)
586 (setq stgit-expanded-patches (delq patchname stgit-expanded-patches))
587 (setq stgit-expanded-patches (cons patchname stgit-expanded-patches)))
588 (ewoc-invalidate stgit-ewoc (ewoc-locate stgit-ewoc)))
589 (move-to-column (stgit-goal-column)))
591 (defun stgit-select ()
592 "With point on a patch, toggle showing files in the patch.
594 With point on a file, open the associated file. Opens the target
595 file for (applied) copies and renames."
597 (case (get-text-property (point) 'entry-type)
599 (stgit-select-patch))
603 (error "No patch or file on line"))))
605 (defun stgit-find-file-other-window ()
606 "Open file at point in other window"
610 (defun stgit-find-file-merge ()
611 "Open file at point and merge it using `smerge-ediff'."
617 "Hide the stgit buffer."
621 (defun stgit-git-status ()
622 "Show status using `git-status'."
624 (unless (fboundp 'git-status)
625 (error "The stgit-git-status command requires git-status"))
626 (let ((dir default-directory))
627 (save-selected-window
631 (defun stgit-goal-column ()
632 "Return goal column for the current line"
633 (case (get-text-property (point) 'entry-type)
638 (defun stgit-next-line (&optional arg)
639 "Move cursor vertically down ARG lines"
642 (move-to-column (stgit-goal-column)))
644 (defun stgit-previous-line (&optional arg)
645 "Move cursor vertically up ARG lines"
648 (move-to-column (stgit-goal-column)))
650 (defun stgit-next-patch (&optional arg)
651 "Move cursor down ARG patches."
653 (ewoc-goto-next stgit-ewoc (or arg 1))
654 (move-to-column goal-column))
656 (defun stgit-previous-patch (&optional arg)
657 "Move cursor up ARG patches."
659 (ewoc-goto-prev stgit-ewoc (or arg 1))
660 (move-to-column goal-column))
662 (defvar stgit-mode-hook nil
663 "Run after `stgit-mode' is setup.")
665 (defvar stgit-mode-map nil
666 "Keymap for StGit major mode.")
668 (unless stgit-mode-map
669 (let ((diff-map (make-keymap))
670 (toggle-map (make-keymap)))
671 (suppress-keymap diff-map)
672 (mapc (lambda (arg) (define-key diff-map (car arg) (cdr arg)))
673 '(("b" . stgit-diff-base)
674 ("c" . stgit-diff-combined)
675 ("m" . stgit-find-file-merge)
676 ("o" . stgit-diff-ours)
677 ("t" . stgit-diff-theirs)))
678 (suppress-keymap toggle-map)
679 (mapc (lambda (arg) (define-key toggle-map (car arg) (cdr arg)))
680 '(("t" . stgit-toggle-worktree)
681 ("i" . stgit-toggle-ignored)
682 ("u" . stgit-toggle-unknown)))
683 (setq stgit-mode-map (make-keymap))
684 (suppress-keymap stgit-mode-map)
685 (mapc (lambda (arg) (define-key stgit-mode-map (car arg) (cdr arg)))
688 ("\d" . stgit-unmark-up)
689 ("u" . stgit-unmark-down)
692 ("\C-p" . stgit-previous-line)
693 ("\C-n" . stgit-next-line)
694 ([up] . stgit-previous-line)
695 ([down] . stgit-next-line)
696 ("p" . stgit-previous-patch)
697 ("n" . stgit-next-patch)
698 ("\M-{" . stgit-previous-patch)
699 ("\M-}" . stgit-next-patch)
700 ("s" . stgit-git-status)
701 ("g" . stgit-reload-or-repair)
702 ("r" . stgit-refresh)
703 ("\C-c\C-r" . stgit-rename)
705 ("M" . stgit-move-patches)
708 ("\C-c\C-c" . stgit-commit)
709 ("\C-c\C-u" . stgit-uncommit)
710 ("U" . stgit-revert-file)
711 ("R" . stgit-resolve-file)
712 ("\r" . stgit-select)
713 ("o" . stgit-find-file-other-window)
714 ("i" . stgit-file-toggle-index)
715 (">" . stgit-push-next)
716 ("<" . stgit-pop-next)
717 ("P" . stgit-push-or-pop)
721 ([(control ?/)] . stgit-undo)
722 ("\C-_" . stgit-undo)
726 ("q" . stgit-quit)))))
729 "Major mode for interacting with StGit.
732 (kill-all-local-variables)
733 (buffer-disable-undo)
734 (setq mode-name "StGit"
735 major-mode 'stgit-mode
737 (use-local-map stgit-mode-map)
738 (set (make-local-variable 'list-buffers-directory) default-directory)
739 (set (make-local-variable 'stgit-marked-patches) nil)
740 (set (make-local-variable 'stgit-expanded-patches) (list :work :index))
741 (set (make-local-variable 'stgit-show-worktree) stgit-default-show-worktree)
742 (set (make-local-variable 'stgit-index-node) nil)
743 (set (make-local-variable 'stgit-worktree-node) nil)
744 (set (make-local-variable 'parse-sexp-lookup-properties) t)
745 (set-variable 'truncate-lines 't)
746 (add-hook 'after-save-hook 'stgit-update-saved-file)
747 (run-hooks 'stgit-mode-hook))
749 (defun stgit-update-saved-file ()
750 (let* ((file (expand-file-name buffer-file-name))
751 (dir (file-name-directory file))
752 (gitdir (condition-case nil (git-get-top-dir dir)
754 (buffer (and gitdir (stgit-find-buffer gitdir))))
756 (with-current-buffer buffer
757 (stgit-refresh-worktree)))))
759 (defun stgit-add-mark (patchsym)
760 "Mark the patch PATCHSYM."
761 (setq stgit-marked-patches (cons patchsym stgit-marked-patches)))
763 (defun stgit-remove-mark (patchsym)
764 "Unmark the patch PATCHSYM."
765 (setq stgit-marked-patches (delq patchsym stgit-marked-patches)))
767 (defun stgit-clear-marks ()
768 "Unmark all patches."
769 (setq stgit-marked-patches '()))
771 (defun stgit-patch-at-point (&optional cause-error)
772 (get-text-property (point) 'patch-data))
774 (defun stgit-patch-name-at-point (&optional cause-error only-patches)
775 "Return the patch name on the current line as a symbol.
776 If CAUSE-ERROR is not nil, signal an error if none found.
777 If ONLY-PATCHES is not nil, only allow real patches, and not
779 (let ((patch (stgit-patch-at-point)))
782 (memq (stgit-patch-status patch) '(work index))
785 (stgit-patch-name patch))
787 (error "No patch on this line")))))
789 (defun stgit-patched-file-at-point ()
790 (get-text-property (point) 'file-data))
792 (defun stgit-patches-marked-or-at-point ()
793 "Return the symbols of the marked patches, or the patch on the current line."
794 (if stgit-marked-patches
796 (let ((patch (stgit-patch-name-at-point)))
801 (defun stgit-goto-patch (patchsym &optional file)
802 "Move point to the line containing patch PATCHSYM.
803 If that patch cannot be found, do nothing.
805 If the patch was found and FILE is not nil, instead move to that
806 file's line. If FILE cannot be found, stay on the line of
808 (let ((node (ewoc-nth stgit-ewoc 0)))
809 (while (and node (not (eq (stgit-patch-name (ewoc-data node))
811 (setq node (ewoc-next stgit-ewoc node)))
812 (when (and node file)
813 (let* ((file-ewoc (stgit-patch-files-ewoc (ewoc-data node)))
814 (file-node (ewoc-nth file-ewoc 0)))
815 (while (and file-node (not (equal (stgit-file-file (ewoc-data file-node)) file)))
816 (setq file-node (ewoc-next file-ewoc file-node)))
818 (ewoc-goto-node file-ewoc file-node)
819 (move-to-column (stgit-goal-column))
822 (ewoc-goto-node stgit-ewoc node)
823 (move-to-column goal-column))))
828 (stgit-capture-output nil
833 "Mark the patch under point."
835 (let* ((node (ewoc-locate stgit-ewoc))
836 (patch (ewoc-data node))
837 (name (stgit-patch-name patch)))
838 (when (eq name :work)
839 (error "Cannot mark the work tree"))
840 (when (eq name :index)
841 (error "Cannot mark the index"))
842 (stgit-add-mark (stgit-patch-name patch))
843 (ewoc-invalidate stgit-ewoc node))
846 (defun stgit-unmark-up ()
847 "Remove mark from the patch on the previous line."
849 (stgit-previous-patch)
850 (let* ((node (ewoc-locate stgit-ewoc))
851 (patch (ewoc-data node)))
852 (stgit-remove-mark (stgit-patch-name patch))
853 (ewoc-invalidate stgit-ewoc node))
854 (move-to-column (stgit-goal-column)))
856 (defun stgit-unmark-down ()
857 "Remove mark from the patch on the current line."
859 (let* ((node (ewoc-locate stgit-ewoc))
860 (patch (ewoc-data node)))
861 (stgit-remove-mark (stgit-patch-name patch))
862 (ewoc-invalidate stgit-ewoc node))
865 (defun stgit-rename (name)
866 "Rename the patch under point to NAME."
868 (read-string "Patch name: "
869 (symbol-name (stgit-patch-name-at-point t t)))))
870 (let ((old-patchsym (stgit-patch-name-at-point t t)))
871 (stgit-capture-output nil
872 (stgit-run "rename" old-patchsym name))
873 (let ((name-sym (intern name)))
874 (when (memq old-patchsym stgit-expanded-patches)
875 (setq stgit-expanded-patches
876 (cons name-sym (delq old-patchsym stgit-expanded-patches))))
877 (when (memq old-patchsym stgit-marked-patches)
878 (setq stgit-marked-patches
879 (cons name-sym (delq old-patchsym stgit-marked-patches))))
881 (stgit-goto-patch name-sym))))
883 (defun stgit-reload-or-repair (repair)
884 "Update the contents of the StGit buffer (`stgit-reload').
886 With a prefix argument, repair the StGit metadata if the branch
887 was modified with git commands (`stgit-repair')."
893 (defun stgit-repair ()
896 (stgit-capture-output nil
897 (stgit-run "repair"))
900 (defun stgit-available-branches ()
901 "Returns a list of the available stg branches"
902 (let ((output (with-output-to-string
903 (stgit-run "branch" "--list")))
906 (while (string-match "^>?\\s-+s\\s-+\\(\\S-+\\)" output start)
907 (setq result (cons (match-string 1 output) result))
908 (setq start (match-end 0)))
911 (defun stgit-branch (branch)
912 "Switch to branch BRANCH."
913 (interactive (list (completing-read "Switch to branch: "
914 (stgit-available-branches))))
915 (stgit-capture-output nil (stgit-run "branch" "--" branch))
918 (defun stgit-commit (count)
919 "Run stg commit on COUNT commits.
920 Interactively, the prefix argument is used as COUNT.
921 A negative COUNT will uncommit instead."
924 (stgit-uncommit (- count))
925 (stgit-capture-output nil (stgit-run "commit" "-n" count))
928 (defun stgit-uncommit (count)
929 "Run stg uncommit on COUNT commits.
930 Interactively, the prefix argument is used as COUNT.
931 A negative COUNT will commit instead."
934 (stgit-commit (- count))
935 (stgit-capture-output nil (stgit-run "uncommit" "-n" count))
938 (defun stgit-revert-file ()
939 "Revert the file at point, which must be in the index or the
942 (let* ((patched-file (or (stgit-patched-file-at-point)
943 (error "No file on the current line")))
944 (patch-name (stgit-patch-name-at-point))
945 (file-status (stgit-file-status patched-file))
946 (rm-file (cond ((stgit-file-copy-or-rename patched-file)
947 (stgit-file-cr-to patched-file))
948 ((eq file-status 'add)
949 (stgit-file-file patched-file))))
950 (co-file (cond ((eq file-status 'rename)
951 (stgit-file-cr-from patched-file))
952 ((not (memq file-status '(copy add)))
953 (stgit-file-file patched-file)))))
955 (unless (memq patch-name '(:work :index))
956 (error "No index or working tree file on this line"))
958 (when (eq file-status 'ignore)
959 (error "Cannot revert ignored files"))
961 (when (eq file-status 'unknown)
962 (error "Cannot revert unknown files"))
964 (let ((nfiles (+ (if rm-file 1 0) (if co-file 1 0))))
965 (when (yes-or-no-p (format "Revert %d file%s? "
967 (if (= nfiles 1) "" "s")))
968 (stgit-capture-output nil
970 (stgit-run-git "rm" "-f" "-q" "--" rm-file))
972 (stgit-run-git "checkout" "HEAD" co-file)))
975 (defun stgit-resolve-file ()
976 "Resolve conflict in the file at point."
978 (let* ((patched-file (stgit-patched-file-at-point))
979 (patch (stgit-patch-at-point))
980 (patch-name (and patch (stgit-patch-name patch)))
981 (status (and patched-file (stgit-file-status patched-file))))
983 (unless (memq patch-name '(:work :index))
984 (error "No index or working tree file on this line"))
986 (unless (eq status 'unmerged)
987 (error "No conflict to resolve at the current line"))
989 (stgit-capture-output nil
990 (stgit-move-change-to-index (stgit-file-file patched-file)))
994 (defun stgit-push-next (npatches)
995 "Push the first unapplied patch.
996 With numeric prefix argument, push that many patches."
998 (stgit-capture-output nil (stgit-run "push" "-n" npatches))
1000 (stgit-refresh-git-status))
1002 (defun stgit-pop-next (npatches)
1003 "Pop the topmost applied patch.
1004 With numeric prefix argument, pop that many patches."
1006 (stgit-capture-output nil (stgit-run "pop" "-n" npatches))
1008 (stgit-refresh-git-status))
1010 (defun stgit-applied-at-point ()
1011 "Is the patch on the current line applied?"
1014 (looking-at "[>+]")))
1016 (defun stgit-push-or-pop ()
1017 "Push or pop the patch on the current line."
1019 (let ((patchsym (stgit-patch-name-at-point t))
1020 (applied (stgit-applied-at-point)))
1021 (stgit-capture-output nil
1022 (stgit-run (if applied "pop" "push") patchsym))
1025 (defun stgit-goto ()
1026 "Go to the patch on the current line."
1028 (let ((patchsym (stgit-patch-name-at-point t)))
1029 (stgit-capture-output nil
1030 (stgit-run "goto" patchsym))
1033 (defun stgit-id (patchsym)
1034 "Return the git commit id for PATCHSYM.
1035 If PATCHSYM is a keyword, returns PATCHSYM unmodified."
1036 (if (keywordp patchsym)
1038 (let ((result (with-output-to-string
1039 (stgit-run-silent "id" patchsym))))
1040 (unless (string-match "^\\([0-9A-Fa-f]\\{40\\}\\)$" result)
1041 (error "Cannot find commit id for %s" patchsym))
1042 (match-string 1 result))))
1044 (defun stgit-show-patch (unmerged-stage ignore-whitespace)
1045 "Show the patch on the current line.
1047 UNMERGED-STAGE is the argument to `git-diff' that that selects
1048 which stage to diff against in the case of unmerged files."
1049 (let ((space-arg (when (numberp ignore-whitespace)
1050 (cond ((> ignore-whitespace 4)
1051 "--ignore-all-space")
1052 ((> ignore-whitespace 1)
1053 "--ignore-space-change"))))
1054 (patch-name (stgit-patch-name-at-point t)))
1055 (stgit-capture-output "*StGit patch*"
1056 (case (get-text-property (point) 'entry-type)
1058 (let* ((patched-file (stgit-patched-file-at-point))
1059 (patch-id (let ((id (stgit-id patch-name)))
1060 (if (and (eq id :index)
1061 (eq (stgit-file-status patched-file)
1065 (args (append (and space-arg (list space-arg))
1066 (and (stgit-file-cr-from patched-file)
1067 (list (stgit-find-copies-harder-diff-arg)))
1068 (cond ((eq patch-id :index)
1070 ((eq patch-id :work)
1071 (list unmerged-stage))
1073 (list (concat patch-id "^") patch-id)))
1075 (if (stgit-file-copy-or-rename patched-file)
1076 (list (stgit-file-cr-from patched-file)
1077 (stgit-file-cr-to patched-file))
1078 (list (stgit-file-file patched-file))))))
1079 (apply 'stgit-run-git "diff" args)))
1081 (let* ((patch-id (stgit-id patch-name)))
1082 (if (or (eq patch-id :index) (eq patch-id :work))
1083 (apply 'stgit-run-git "diff"
1084 (stgit-find-copies-harder-diff-arg)
1085 (append (and space-arg (list space-arg))
1086 (if (eq patch-id :index)
1088 (list unmerged-stage))))
1089 (let ((args (append '("show" "-O" "--patch-with-stat" "-O" "-M")
1090 (and space-arg (list "-O" space-arg))
1091 (list (stgit-patch-name-at-point)))))
1092 (apply 'stgit-run args)))))
1094 (error "No patch or file at point")))
1095 (with-current-buffer standard-output
1096 (goto-char (point-min))
1099 (defmacro stgit-define-diff (name diff-arg &optional unmerged-action)
1100 `(defun ,name (&optional ignore-whitespace)
1101 ,(format "Show the patch on the current line.
1103 %sWith a prefix argument, ignore whitespace. With a prefix argument
1104 greater than four (e.g., \\[universal-argument] \
1105 \\[universal-argument] \\[%s]), ignore all whitespace."
1107 (format "For unmerged files, %s.\n\n" unmerged-action)
1111 (stgit-show-patch ,diff-arg ignore-whitespace)))
1113 (stgit-define-diff stgit-diff
1115 (stgit-define-diff stgit-diff-ours
1117 "diff against our branch")
1118 (stgit-define-diff stgit-diff-theirs
1120 "diff against their branch")
1121 (stgit-define-diff stgit-diff-base
1123 "diff against the merge base")
1124 (stgit-define-diff stgit-diff-combined
1126 "show a combined diff")
1128 (defun stgit-move-change-to-index (file)
1129 "Copies the workspace state of FILE to index, using git add or git rm"
1130 (let ((op (if (or (file-exists-p file) (file-symlink-p file))
1131 '("add") '("rm" "-q"))))
1132 (stgit-capture-output "*git output*"
1133 (apply 'stgit-run-git (append op '("--") (list file))))))
1135 (defun stgit-remove-change-from-index (file)
1136 "Unstages the change in FILE from the index"
1137 (stgit-capture-output "*git output*"
1138 (stgit-run-git "reset" "-q" "--" file)))
1140 (defun stgit-file-toggle-index ()
1141 "Move modified file in or out of the index.
1143 Leaves the point where it is, but moves the mark to where the
1144 file ended up. You can then jump to the file with \
1145 \\[exchange-point-and-mark]."
1147 (let ((patched-file (stgit-patched-file-at-point)))
1148 (unless patched-file
1149 (error "No file on the current line"))
1150 (when (eq (stgit-file-status patched-file) 'unmerged)
1151 (error (substitute-command-keys "Use \\[stgit-resolve-file] to move an unmerged file to the index")))
1152 (when (eq (stgit-file-status patched-file) 'ignore)
1153 (error "You cannot add ignored files to the index"))
1154 (let* ((patch (stgit-patch-at-point))
1155 (patch-name (stgit-patch-name patch))
1159 ;; find the next file in the patch, or the previous one if this
1160 ;; was the last file
1161 (and (zerop (forward-line 1))
1162 (let ((f (stgit-patched-file-at-point)))
1163 (and f (setq next-file (stgit-file-file f)))))
1164 (goto-char old-point)
1166 (and (zerop (forward-line -1))
1167 (let ((f (stgit-patched-file-at-point)))
1168 (and f (setq next-file (stgit-file-file f)))))
1169 (goto-char old-point))
1171 (cond ((eq patch-name :work)
1172 (stgit-move-change-to-index (stgit-file-file patched-file)))
1173 ((eq patch-name :index)
1174 (stgit-remove-change-from-index (stgit-file-file patched-file)))
1176 (error "Can only move files in the working tree to index")))
1177 (stgit-refresh-worktree)
1178 (stgit-refresh-index)
1179 (stgit-goto-patch (if (eq patch-name :index) :work :index)
1180 (stgit-file-file patched-file))
1182 (stgit-goto-patch patch-name next-file))))
1184 (defun stgit-edit ()
1185 "Edit the patch on the current line."
1187 (let ((patchsym (stgit-patch-name-at-point t t))
1188 (edit-buf (get-buffer-create "*StGit edit*"))
1189 (dir default-directory))
1190 (log-edit 'stgit-confirm-edit t nil edit-buf)
1191 (set (make-local-variable 'stgit-edit-patchsym) patchsym)
1192 (setq default-directory dir)
1193 (let ((standard-output edit-buf))
1194 (stgit-run-silent "edit" "--save-template=-" patchsym))))
1196 (defun stgit-confirm-edit ()
1198 (let ((file (make-temp-file "stgit-edit-")))
1199 (write-region (point-min) (point-max) file)
1200 (stgit-capture-output nil
1201 (stgit-run "edit" "-f" file stgit-edit-patchsym))
1202 (with-current-buffer log-edit-parent-buffer
1205 (defun stgit-new (add-sign)
1206 "Create a new patch.
1207 With a prefix argument, include a \"Signed-off-by:\" line at the
1210 (let ((edit-buf (get-buffer-create "*StGit edit*"))
1211 (dir default-directory))
1212 (log-edit 'stgit-confirm-new t nil edit-buf)
1213 (setq default-directory dir)
1216 (let ((standard-output (current-buffer)))
1217 (stgit-run-silent "new" "--sign" "--save-template=-"))))))
1219 (defun stgit-confirm-new ()
1221 (let ((file (make-temp-file "stgit-edit-")))
1222 (write-region (point-min) (point-max) file)
1223 (stgit-capture-output nil
1224 (stgit-run "new" "-f" file))
1225 (with-current-buffer log-edit-parent-buffer
1228 (defun stgit-create-patch-name (description)
1229 "Create a patch name from a long description"
1231 (while (> (length description) 0)
1232 (cond ((string-match "\\`[a-zA-Z_-]+" description)
1233 (setq patch (downcase (concat patch
1234 (match-string 0 description))))
1235 (setq description (substring description (match-end 0))))
1236 ((string-match "\\` +" description)
1237 (setq patch (concat patch "-"))
1238 (setq description (substring description (match-end 0))))
1239 ((string-match "\\`[^a-zA-Z_-]+" description)
1240 (setq description (substring description (match-end 0))))))
1241 (cond ((= (length patch) 0)
1243 ((> (length patch) 20)
1244 (substring patch 0 20))
1247 (defun stgit-delete (patchsyms &optional spill-p)
1248 "Delete the patches in PATCHSYMS.
1249 Interactively, delete the marked patches, or the patch at point.
1251 With a prefix argument, or SPILL-P, spill the patch contents to
1252 the work tree and index."
1253 (interactive (list (stgit-patches-marked-or-at-point)
1254 current-prefix-arg))
1256 (error "No patches to delete"))
1257 (when (memq :index patchsyms)
1258 (error "Cannot delete the index"))
1259 (when (memq :work patchsyms)
1260 (error "Cannot delete the work tree"))
1262 (let ((npatches (length patchsyms)))
1263 (when (yes-or-no-p (format "Really delete %d patch%s%s? "
1265 (if (= 1 npatches) "" "es")
1267 " (spilling contents to index)"
1269 (let ((args (if spill-p
1270 (cons "--spill" patchsyms)
1272 (stgit-capture-output nil
1273 (apply 'stgit-run "delete" args))
1276 (defun stgit-move-patches-target ()
1277 "Return the patchsym indicating a target patch for
1278 `stgit-move-patches'.
1280 This is either the patch at point, or one of :top and :bottom, if
1281 the point is after or before the applied patches."
1283 (let ((patchsym (stgit-patch-name-at-point)))
1284 (cond (patchsym patchsym)
1285 ((save-excursion (re-search-backward "^>" nil t)) :top)
1288 (defun stgit-sort-patches (patchsyms)
1289 "Returns the list of patches in PATCHSYMS sorted according to
1290 their position in the patch series, bottommost first.
1292 PATCHSYMS may not contain duplicate entries."
1293 (let (sorted-patchsyms
1294 (series (with-output-to-string
1295 (with-current-buffer standard-output
1296 (stgit-run-silent "series" "--noprefix"))))
1298 (while (string-match "^\\(.+\\)" series start)
1299 (let ((patchsym (intern (match-string 1 series))))
1300 (when (memq patchsym patchsyms)
1301 (setq sorted-patchsyms (cons patchsym sorted-patchsyms))))
1302 (setq start (match-end 0)))
1303 (setq sorted-patchsyms (nreverse sorted-patchsyms))
1305 (unless (= (length patchsyms) (length sorted-patchsyms))
1306 (error "Internal error"))
1310 (defun stgit-move-patches (patchsyms target-patch)
1311 "Move the patches in PATCHSYMS to below TARGET-PATCH.
1312 If TARGET-PATCH is :bottom or :top, move the patches to the
1313 bottom or top of the stack, respectively.
1315 Interactively, move the marked patches to where the point is."
1316 (interactive (list stgit-marked-patches
1317 (stgit-move-patches-target)))
1319 (error "Need at least one patch to move"))
1321 (unless target-patch
1322 (error "Point not at a patch"))
1324 (if (eq target-patch :top)
1325 (stgit-capture-output nil
1326 (apply 'stgit-run "float" patchsyms))
1328 ;; need to have patchsyms sorted by position in the stack
1329 (let ((sorted-patchsyms (stgit-sort-patches patchsyms)))
1330 (while sorted-patchsyms
1331 (setq sorted-patchsyms
1332 (and (stgit-capture-output nil
1333 (if (eq target-patch :bottom)
1334 (stgit-run "sink" "--" (car sorted-patchsyms))
1335 (stgit-run "sink" "--to" target-patch "--"
1336 (car sorted-patchsyms))))
1337 (cdr sorted-patchsyms))))))
1340 (defun stgit-squash (patchsyms)
1341 "Squash the patches in PATCHSYMS.
1342 Interactively, squash the marked patches.
1344 Unless there are any conflicts, the patches will be merged into
1345 one patch, which will occupy the same spot in the series as the
1346 deepest patch had before the squash."
1347 (interactive (list stgit-marked-patches))
1348 (when (< (length patchsyms) 2)
1349 (error "Need at least two patches to squash"))
1350 (let ((stgit-buffer (current-buffer))
1351 (edit-buf (get-buffer-create "*StGit edit*"))
1352 (dir default-directory)
1353 (sorted-patchsyms (stgit-sort-patches patchsyms)))
1354 (log-edit 'stgit-confirm-squash t nil edit-buf)
1355 (set (make-local-variable 'stgit-patchsyms) sorted-patchsyms)
1356 (setq default-directory dir)
1357 (let ((result (let ((standard-output edit-buf))
1358 (apply 'stgit-run-silent "squash"
1359 "--save-template=-" sorted-patchsyms))))
1361 ;; stg squash may have reordered the patches or caused conflicts
1362 (with-current-buffer stgit-buffer
1365 (unless (eq 0 result)
1367 (rename-buffer "*StGit error*")
1368 (resize-temp-buffer-window)
1369 (switch-to-buffer-other-window stgit-buffer)
1370 (error "stg squash failed")))))
1372 (defun stgit-confirm-squash ()
1374 (let ((file (make-temp-file "stgit-edit-")))
1375 (write-region (point-min) (point-max) file)
1376 (stgit-capture-output nil
1377 (apply 'stgit-run "squash" "-f" file stgit-patchsyms))
1378 (with-current-buffer log-edit-parent-buffer
1380 ;; Go to first marked patch and stay there
1381 (goto-char (point-min))
1382 (re-search-forward (concat "^[>+-]\\*") nil t)
1383 (move-to-column goal-column)
1384 (let ((pos (point)))
1388 (defun stgit-help ()
1389 "Display help for the StGit mode."
1391 (describe-function 'stgit-mode))
1393 (defun stgit-undo (&optional arg)
1395 With prefix argument, run it with the --hard flag."
1397 (stgit-capture-output nil
1399 (stgit-run "undo" "--hard")
1400 (stgit-run "undo")))
1403 (defun stgit-refresh (&optional arg)
1405 If the index contains any changes, only refresh from index.
1407 With prefix argument, refresh the marked patch or the patch under point."
1409 (let ((patchargs (if arg
1410 (let ((patches (stgit-patches-marked-or-at-point)))
1411 (cond ((null patches)
1412 (error "No patch to update"))
1413 ((> (length patches) 1)
1414 (error "Too many patches selected"))
1416 (cons "-p" patches))))
1418 (unless (stgit-index-empty-p)
1419 (setq patchargs (cons "--index" patchargs)))
1420 (stgit-capture-output nil
1421 (apply 'stgit-run "refresh" patchargs))
1422 (stgit-refresh-git-status))
1425 (defcustom stgit-show-worktree-mode 'center
1426 "This variable controls where the \"Index\" and \"Work tree\"
1427 will be shown on in the buffer.
1429 It can be set to 'top (above all patches), 'center (show between
1430 applied and unapplied patches), and 'bottom (below all patches).
1432 See also `stgit-show-worktree'."
1433 :type '(radio (const :tag "above all patches (top)" top)
1434 (const :tag "between applied and unapplied patches (center)"
1436 (const :tag "below all patches (bottom)" bottom))
1439 (defcustom stgit-default-show-worktree
1441 "Set to non-nil to by default show the working tree in a new stgit buffer.
1443 This value is used as the default value for `stgit-show-worktree'."
1447 (defvar stgit-show-worktree nil
1448 "If nil, inhibit showing work tree and index in the stgit buffer.
1450 See also `stgit-show-worktree-mode'.")
1452 (defvar stgit-show-ignored nil
1453 "If nil, inhibit showing files ignored by git.")
1455 (defvar stgit-show-unknown nil
1456 "If nil, inhibit showing files not registered with git.")
1458 (defun stgit-toggle-worktree (&optional arg)
1459 "Toggle the visibility of the work tree.
1460 With arg, show the work tree if arg is positive.
1462 Its initial setting is controlled by `stgit-default-show-worktree'.
1464 `stgit-show-worktree-mode' controls where on screen the index and
1465 work tree will show up."
1467 (setq stgit-show-worktree
1470 (not stgit-show-worktree)))
1473 (defun stgit-toggle-ignored (&optional arg)
1474 "Toggle the visibility of files ignored by git in the work
1475 tree. With ARG, show these files if ARG is positive.
1477 Use \\[stgit-toggle-worktree] to show the work tree."
1479 (setq stgit-show-ignored
1482 (not stgit-show-ignored)))
1485 (defun stgit-toggle-unknown (&optional arg)
1486 "Toggle the visibility of files not registered with git in the
1487 work tree. With ARG, show these files if ARG is positive.
1489 Use \\[stgit-toggle-worktree] to show the work tree."
1491 (setq stgit-show-unknown
1494 (not stgit-show-unknown)))