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'
12 (when (< emacs-major-version 22)
13 (error "Emacs older than 22 is not supported by stgit.el"))
19 (require 'format-spec)
21 (defun stgit-set-default (symbol value)
22 "Set default value of SYMBOL to VALUE using `set-default' and
23 reload all StGit buffers."
24 (set-default symbol value)
25 (dolist (buf (buffer-list))
26 (with-current-buffer buf
27 (when (eq major-mode 'stgit-mode)
31 "A user interface for the StGit patch maintenance tool."
33 :link '(function-link stgit)
34 :link '(url-link "http://www.procode.org/stgit/"))
36 (defcustom stgit-abbreviate-copies-and-renames t
37 "If non-nil, abbreviate copies and renames as \"dir/{old -> new}/file\"
38 instead of \"dir/old/file -> dir/new/file\"."
41 :set 'stgit-set-default)
43 (defcustom stgit-default-show-worktree t
44 "Set to non-nil to by default show the working tree in a new stgit buffer.
46 Use \\<stgit-mode-map>\\[stgit-toggle-worktree] to toggle the this setting in an already-started StGit buffer."
49 :link '(variable-link stgit-show-worktree))
51 (defcustom stgit-find-copies-harder nil
52 "Try harder to find copied files when listing patches.
54 When not nil, runs git diff-tree with the --find-copies-harder
55 flag, which reduces performance."
58 :set 'stgit-set-default)
60 (defcustom stgit-show-worktree-mode 'center
61 "This variable controls where the \"Index\" and \"Work tree\"
62 will be shown on in the buffer.
64 It can be set to 'top (above all patches), 'center (show between
65 applied and unapplied patches), and 'bottom (below all patches)."
66 :type '(radio (const :tag "above all patches (top)" top)
67 (const :tag "between applied and unapplied patches (center)"
69 (const :tag "below all patches (bottom)" bottom))
71 :link '(variable-link stgit-show-worktree)
72 :set 'stgit-set-default)
74 (defcustom stgit-patch-line-format "%s%m%-30n %e%d"
75 "The format string used to format patch lines.
76 The format string is passed to `format-spec' and the following
77 format characters are recognized:
79 %s - A '+', '-', '>' or space, depending on whether the patch is
80 applied, unapplied, top, or something else.
82 %m - An asterisk if the patch is marked, and a space otherwise.
86 %e - The string \"(empty) \" if the patch is empty.
88 %d - The short patch description.
90 %D - The short patch description, or the patch name.
92 When `stgit-show-patch-names' is non-nil, the `stgit-noname-patch-line-format'
93 variable is used instead."
96 :set 'stgit-set-default)
98 (defcustom stgit-noname-patch-line-format "%s%m%e%D"
99 "The alternate format string used to format patch lines.
100 It has the same semantics as `stgit-patch-line-format', and the
101 display can be toggled between the two formats using
102 \\<stgit-mode-map>>\\[stgit-toggle-patch-names].
104 The alternate form is used when the patch name is hidden."
107 :set 'stgit-set-default)
109 (defcustom stgit-default-show-patch-names t
110 "If non-nil, default to showing patch names in a new stgit buffer.
112 Use \\<stgit-mode-map>\\[stgit-toggle-patch-names] to toggle the
113 this setting in an already-started StGit buffer."
116 :link '(variable-link stgit-show-patch-names))
118 (defcustom stgit-file-line-format " %-11s %-2m %n %c"
119 "The format string used to format file lines.
120 The format string is passed to `format-spec' and the following
121 format characters are recognized:
123 %s - A string describing the status of the file.
125 %m - Mode change information
129 %c - A description of file changes."
132 :set 'stgit-set-default)
134 (defface stgit-branch-name-face
136 "The face used for the StGit branch name"
139 (defface stgit-top-patch-face
140 '((((background dark)) (:weight bold :foreground "yellow"))
141 (((background light)) (:weight bold :foreground "purple"))
143 "The face used for the top patch names"
146 (defface stgit-applied-patch-face
147 '((((background dark)) (:foreground "light yellow"))
148 (((background light)) (:foreground "purple"))
150 "The face used for applied patch names"
153 (defface stgit-unapplied-patch-face
154 '((((background dark)) (:foreground "gray80"))
155 (((background light)) (:foreground "orchid"))
157 "The face used for unapplied patch names"
160 (defface stgit-description-face
161 '((((background dark)) (:foreground "tan"))
162 (((background light)) (:foreground "dark red")))
163 "The face used for StGit descriptions"
166 (defface stgit-index-work-tree-title-face
167 '((((supports :slant italic)) :slant italic)
169 "StGit mode face used for the \"Index\" and \"Work tree\" titles"
172 (defface stgit-unmerged-file-face
173 '((((class color) (background light)) (:foreground "red" :bold t))
174 (((class color) (background dark)) (:foreground "red" :bold t)))
175 "StGit mode face used for unmerged file status"
178 (defface stgit-unknown-file-face
179 '((((class color) (background light)) (:foreground "goldenrod" :bold t))
180 (((class color) (background dark)) (:foreground "goldenrod" :bold t)))
181 "StGit mode face used for unknown file status"
184 (defface stgit-ignored-file-face
185 '((((class color) (background light)) (:foreground "grey60"))
186 (((class color) (background dark)) (:foreground "grey40")))
187 "StGit mode face used for ignored files")
189 (defface stgit-file-permission-face
190 '((((class color) (background light)) (:foreground "green" :bold t))
191 (((class color) (background dark)) (:foreground "green" :bold t)))
192 "StGit mode face used for permission changes."
195 (defface stgit-modified-file-face
196 '((((class color) (background light)) (:foreground "purple"))
197 (((class color) (background dark)) (:foreground "salmon")))
198 "StGit mode face used for modified file status"
202 "Manage StGit patches for the tree in DIR.
204 See `stgit-mode' for commands available."
205 (interactive "DDirectory: \n")
206 (switch-to-stgit-buffer (git-get-top-dir dir))
209 (defun stgit-assert-mode ()
210 "Signal an error if not in an StGit buffer."
211 (assert (derived-mode-p 'stgit-mode) nil "Not an StGit buffer"))
213 (unless (fboundp 'git-get-top-dir)
214 (defun git-get-top-dir (dir)
215 "Retrieve the top-level directory of a git tree."
216 (let ((cdup (with-output-to-string
217 (with-current-buffer standard-output
219 (unless (eq 0 (call-process "git" nil t nil
220 "rev-parse" "--show-cdup"))
221 (error "Cannot find top-level git tree for %s" dir))))))
222 (expand-file-name (concat (file-name-as-directory dir)
223 (car (split-string cdup "\n")))))))
225 (defun stgit-refresh-git-status (&optional dir)
226 "If it exists, refresh the `git-status' buffer belonging to
227 directory DIR or `default-directory'"
228 (when (and (fboundp 'git-find-status-buffer)
229 (fboundp 'git-refresh-status))
230 (let* ((top-dir (git-get-top-dir (or dir default-directory)))
231 (git-status-buffer (and top-dir (git-find-status-buffer top-dir))))
232 (when git-status-buffer
233 (with-current-buffer git-status-buffer
234 (git-refresh-status))))))
236 (defun stgit-find-buffer (dir)
237 "Return the buffer displaying StGit patches for DIR, or nil if none."
238 (setq dir (file-name-as-directory dir))
239 (let ((buffers (buffer-list)))
241 (not (with-current-buffer (car buffers)
242 (and (eq major-mode 'stgit-mode)
243 (string= default-directory dir)))))
244 (setq buffers (cdr buffers)))
245 (and buffers (car buffers))))
247 (defun switch-to-stgit-buffer (dir)
248 "Switch to a (possibly new) buffer displaying StGit patches for DIR."
249 (setq dir (file-name-as-directory dir))
250 (let ((buffer (stgit-find-buffer dir)))
251 (switch-to-buffer (or buffer
252 (create-stgit-buffer dir)))))
254 (defstruct (stgit-patch
255 (:conc-name stgit-patch->))
256 status name desc empty files-ewoc)
258 (defun stgit-patch-display-name (patch)
259 (let ((name (stgit-patch->name patch)))
263 (t (symbol-name name)))))
265 (defun stgit-patch-pp (patch)
266 (let* ((status (stgit-patch->status patch))
268 (name (stgit-patch->name patch))
269 (face (cdr (assq status stgit-patch-status-face-alist)))
270 (fmt (if stgit-show-patch-names
271 stgit-patch-line-format
272 stgit-noname-patch-line-format))
273 (spec (format-spec-make
279 ?m (if (memq name stgit-marked-patches)
281 ?n (propertize (stgit-patch-display-name patch)
283 'syntax-table (string-to-syntax "w"))
284 ?e (if (stgit-patch->empty patch) "(empty) " "")
285 ?d (propertize (or (stgit-patch->desc patch) "")
286 'face 'stgit-description-face)
287 ?D (propertize (or (stgit-patch->desc patch)
288 (stgit-patch-display-name patch))
291 (insert (format-spec fmt spec) "\n")
292 (put-text-property start (point) 'entry-type 'patch)
293 (when (memq name stgit-expanded-patches)
294 (stgit-insert-patch-files patch))
295 (put-text-property start (point) 'patch-data patch)))
297 (defun create-stgit-buffer (dir)
298 "Create a buffer for showing StGit patches.
299 Argument DIR is the repository path."
300 (let ((buf (create-file-buffer (concat dir "*stgit*")))
301 (inhibit-read-only t))
302 (with-current-buffer buf
303 (setq default-directory dir)
305 (set (make-local-variable 'stgit-ewoc)
306 (ewoc-create #'stgit-patch-pp "Branch:\n\n" "--\n" t))
307 (setq buffer-read-only t))
310 (defmacro stgit-capture-output (name &rest body)
311 "Capture StGit output and, if there was any output, show it in a window
313 Returns nil if there was no output."
314 (declare (debug ([&or stringp null] body))
316 `(let ((output-buf (get-buffer-create ,(or name "*StGit output*")))
317 (stgit-dir default-directory)
318 (inhibit-read-only t))
319 (with-current-buffer output-buf
320 (buffer-disable-undo)
322 (setq default-directory stgit-dir)
323 (setq buffer-read-only t))
324 (let ((standard-output output-buf))
326 (with-current-buffer output-buf
327 (set-buffer-modified-p nil)
328 (setq buffer-read-only t)
329 (if (< (point-min) (point-max))
330 (display-buffer output-buf t)))))
332 (defun stgit-make-run-args (args)
333 "Return a copy of ARGS with its elements converted to strings."
335 ;; don't use (format "%s" ...) to limit type errors
336 (cond ((stringp x) x)
337 ((integerp x) (number-to-string x))
338 ((symbolp x) (symbol-name x))
340 (error "Bad element in stgit-make-run-args args: %S" x))))
343 (defun stgit-run-silent (&rest args)
344 (setq args (stgit-make-run-args args))
345 (apply 'call-process "stg" nil standard-output nil args))
347 (defun stgit-run (&rest args)
348 (setq args (stgit-make-run-args args))
349 (let ((msgcmd (mapconcat #'identity args " ")))
350 (message "Running stg %s..." msgcmd)
351 (apply 'call-process "stg" nil standard-output nil args)
352 (message "Running stg %s...done" msgcmd)))
354 (defun stgit-run-git (&rest args)
355 (setq args (stgit-make-run-args args))
356 (let ((msgcmd (mapconcat #'identity args " ")))
357 (message "Running git %s..." msgcmd)
358 (apply 'call-process "git" nil standard-output nil args)
359 (message "Running git %s...done" msgcmd)))
361 (defun stgit-run-git-silent (&rest args)
362 (setq args (stgit-make-run-args args))
363 (apply 'call-process "git" nil standard-output nil args))
365 (defun stgit-index-empty-p ()
366 "Returns non-nil if the index contains no changes from HEAD."
367 (zerop (stgit-run-git-silent "diff-index" "--cached" "--quiet" "HEAD")))
369 (defun stgit-work-tree-empty-p ()
370 "Returns non-nil if the work tree contains no changes from index."
371 (zerop (stgit-run-git-silent "diff-files" "--quiet")))
373 (defvar stgit-index-node)
374 (defvar stgit-worktree-node)
376 (defconst stgit-allowed-branch-name-re
377 ;; Disallow control characters, space, del, and "/:@^{}~" in
378 ;; "/"-separated parts; parts may not start with a period (.)
379 "^[^\0- ./:@^{}~\177][^\0- /:@^{}~\177]*\
380 \\(/[^\0- ./:@^{}~\177][^\0- /:@^{}~\177]*\\)*$"
381 "Regular expression that (new) branch names must match.")
383 (defun stgit-refresh-index ()
384 (when stgit-index-node
385 (ewoc-invalidate (car stgit-index-node) (cdr stgit-index-node))))
387 (defun stgit-refresh-worktree ()
388 (when stgit-worktree-node
389 (ewoc-invalidate (car stgit-worktree-node) (cdr stgit-worktree-node))))
391 (defun stgit-run-series-insert-index (ewoc)
392 (setq index-node (cons ewoc (ewoc-enter-last ewoc
398 worktree-node (cons ewoc (ewoc-enter-last ewoc
405 (defun stgit-run-series (ewoc)
406 (setq stgit-index-node nil
407 stgit-worktree-node nil)
408 (let ((inserted-index (not stgit-show-worktree))
413 (let* ((standard-output (current-buffer))
414 (exit-status (stgit-run-silent "series"
415 "--description" "--empty")))
416 (goto-char (point-min))
417 (if (not (zerop exit-status))
418 (cond ((looking-at "stg series: \\(.*\\)")
419 (setq inserted-index t)
420 (ewoc-set-hf ewoc (car (ewoc-get-hf ewoc))
421 (substitute-command-keys
422 "-- not initialized; run \\[stgit-init]")))
424 (error "Error running stg: %s"
428 "\\([0 ]\\)\\([>+-]\\)\\( \\)\\([^ ]+\\) *[|#] \\(.*\\)")
429 (error "Syntax error in output from stg series"))
430 (let* ((state-str (match-string 2))
431 (state (cond ((string= state-str ">") 'top)
432 ((string= state-str "+") 'applied)
433 ((string= state-str "-") 'unapplied)))
434 (name (intern (match-string 4)))
435 (desc (match-string 5))
436 (empty (string= (match-string 1) "0")))
437 (unless inserted-index
438 (when (or (eq stgit-show-worktree-mode 'top)
439 (and (eq stgit-show-worktree-mode 'center)
440 (eq state 'unapplied)))
441 (setq inserted-index t)
442 (stgit-run-series-insert-index ewoc)))
443 (setq all-patchsyms (cons name all-patchsyms))
444 (ewoc-enter-last ewoc
451 (unless inserted-index
452 (stgit-run-series-insert-index ewoc)))
453 (setq stgit-index-node index-node
454 stgit-worktree-node worktree-node
455 stgit-marked-patches (intersection stgit-marked-patches
458 (defun stgit-current-branch ()
459 "Return the name of the current branch."
460 (substring (with-output-to-string
461 (stgit-run-silent "branch"))
464 (defun stgit-reload ()
465 "Update the contents of the StGit buffer."
468 (let ((inhibit-read-only t)
469 (curline (line-number-at-pos))
470 (curpatch (stgit-patch-name-at-point))
471 (curfile (stgit-patched-file-at-point)))
472 (ewoc-filter stgit-ewoc #'(lambda (x) nil))
473 (ewoc-set-hf stgit-ewoc
475 (propertize (stgit-current-branch)
476 'face 'stgit-branch-name-face)
478 (if stgit-show-worktree
481 (substitute-command-keys "--\n\"\\[stgit-toggle-worktree]\"\
482 shows the working tree\n")
483 'face 'stgit-description-face)))
484 (stgit-run-series stgit-ewoc)
486 (stgit-goto-patch curpatch (and curfile (stgit-file->file curfile)))
487 (goto-line curline)))
488 (stgit-refresh-git-status))
490 (defconst stgit-file-status-code-strings
491 (mapcar (lambda (arg)
493 (propertize (cadr arg) 'face (car (cddr arg)))))
494 '((add "Added" stgit-modified-file-face)
495 (copy "Copied" stgit-modified-file-face)
496 (delete "Deleted" stgit-modified-file-face)
497 (modify "Modified" stgit-modified-file-face)
498 (rename "Renamed" stgit-modified-file-face)
499 (mode-change "Mode change" stgit-modified-file-face)
500 (unmerged "Unmerged" stgit-unmerged-file-face)
501 (unknown "Unknown" stgit-unknown-file-face)
502 (ignore "Ignored" stgit-ignored-file-face)))
503 "Alist of code symbols to description strings")
505 (defconst stgit-patch-status-face-alist
506 '((applied . stgit-applied-patch-face)
507 (top . stgit-top-patch-face)
508 (unapplied . stgit-unapplied-patch-face)
509 (index . stgit-index-work-tree-title-face)
510 (work . stgit-index-work-tree-title-face))
511 "Alist of face to use for a given patch status")
513 (defun stgit-file-status-code-as-string (file)
514 "Return stgit status code for FILE as a string"
515 (let* ((code (assq (stgit-file->status file)
516 stgit-file-status-code-strings))
517 (score (stgit-file->cr-score file)))
519 (if (and score (/= score 100))
520 (format "%s %s" (cdr code)
521 (propertize (format "%d%%" score)
522 'face 'stgit-description-face))
525 (defun stgit-file-status-code (str &optional score)
526 "Return stgit status code from git status string"
527 (let ((code (assoc str '(("A" . add)
536 (setq code (if code (cdr code) 'unknown))
537 (when (stringp score)
538 (if (> (length score) 0)
539 (setq score (string-to-number score))
541 (if score (cons code score) code)))
543 (defconst stgit-file-type-strings
546 (#o160 . "subproject"))
547 "Alist of names of file types")
549 (defun stgit-file-type-string (type)
550 "Return string describing file type TYPE (the high bits of file permission).
551 Cf. `stgit-file-type-strings' and `stgit-file-type-change-string'."
552 (let ((type-str (assoc type stgit-file-type-strings)))
553 (or (and type-str (cdr type-str))
554 (format "unknown type %o" type))))
556 (defun stgit-file-type-change-string (old-perm new-perm)
557 "Return string describing file type change from OLD-PERM to NEW-PERM.
558 Cf. `stgit-file-type-string'."
559 (let ((old-type (lsh old-perm -9))
560 (new-type (lsh new-perm -9)))
561 (cond ((= old-type new-type) "")
562 ((zerop new-type) "")
564 (if (= new-type #o100)
566 (format "(%s)" (stgit-file-type-string new-type))))
567 (t (format "(%s -> %s)"
568 (stgit-file-type-string old-type)
569 (stgit-file-type-string new-type))))))
571 (defun stgit-file-mode-change-string (old-perm new-perm)
572 "Return string describing file mode change from OLD-PERM to NEW-PERM.
573 Cf. `stgit-file-type-change-string'."
574 (setq old-perm (logand old-perm #o777)
575 new-perm (logand new-perm #o777))
576 (if (or (= old-perm new-perm)
580 (let* ((modified (logxor old-perm new-perm))
581 (not-x-modified (logand (logxor old-perm new-perm) #o666)))
582 (cond ((zerop modified) "")
583 ((and (zerop not-x-modified)
584 (or (and (eq #o111 (logand old-perm #o111))
585 (propertize "-x" 'face 'stgit-file-permission-face))
586 (and (eq #o111 (logand new-perm #o111))
587 (propertize "+x" 'face
588 'stgit-file-permission-face)))))
589 (t (concat (propertize (format "%o" old-perm)
590 'face 'stgit-file-permission-face)
592 'face 'stgit-description-face)
593 (propertize (format "%o" new-perm)
594 'face 'stgit-file-permission-face)))))))
596 (defstruct (stgit-file
597 (:conc-name stgit-file->))
598 old-perm new-perm copy-or-rename cr-score cr-from cr-to status file)
600 (defun stgit-describe-copy-or-rename (file)
601 (let ((arrow (concat " " (propertize "->" 'face 'stgit-description-face) " "))
602 from to common-head common-tail)
604 (when stgit-abbreviate-copies-and-renames
605 (setq from (split-string (stgit-file->cr-from file) "/")
606 to (split-string (stgit-file->cr-to file) "/"))
608 (while (and from to (cdr from) (cdr to)
609 (string-equal (car from) (car to)))
610 (setq common-head (cons (car from) common-head)
613 (setq common-head (nreverse common-head)
616 (while (and from to (cdr from) (cdr to)
617 (string-equal (car from) (car to)))
618 (setq common-tail (cons (car from) common-tail)
621 (setq from (nreverse from)
624 (if (or common-head common-tail)
625 (concat (if common-head
626 (mapconcat #'identity common-head "/")
628 (if common-head "/" "")
629 (propertize "{" 'face 'stgit-description-face)
630 (mapconcat #'identity from "/")
632 (mapconcat #'identity to "/")
633 (propertize "}" 'face 'stgit-description-face)
634 (if common-tail "/" "")
636 (mapconcat #'identity common-tail "/")
638 (concat (stgit-file->cr-from file) arrow (stgit-file->cr-to file)))))
640 (defun stgit-file-pp (file)
641 (let ((start (point))
642 (spec (format-spec-make
643 ?s (stgit-file-status-code-as-string file)
644 ?m (stgit-file-mode-change-string
645 (stgit-file->old-perm file)
646 (stgit-file->new-perm file))
647 ?n (if (stgit-file->copy-or-rename file)
648 (stgit-describe-copy-or-rename file)
649 (stgit-file->file file))
650 ?c (propertize (stgit-file-type-change-string
651 (stgit-file->old-perm file)
652 (stgit-file->new-perm file))
653 'face 'stgit-description-face))))
654 (insert (format-spec stgit-file-line-format spec) "\n")
655 (add-text-properties start (point)
656 (list 'entry-type 'file
659 (defun stgit-find-copies-harder-diff-arg ()
660 "Return the flag to use with `git-diff' depending on the
661 `stgit-find-copies-harder' flag."
662 (if stgit-find-copies-harder "--find-copies-harder" "-C"))
664 (defun stgit-insert-ls-files (args file-flag)
665 (let ((start (point)))
666 (apply 'stgit-run-git
667 (append '("ls-files" "--exclude-standard" "-z") args))
669 (while (looking-at "\\([^\0]*\\)\0")
670 (let ((name-len (- (match-end 0) (match-beginning 0))))
671 (insert ":0 0 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 " file-flag "\0")
672 (forward-char name-len)))))
674 (defun stgit-process-files (callback)
675 (goto-char (point-min))
676 (when (looking-at "[0-9A-Fa-f]\\{40\\}\0")
677 (goto-char (match-end 0)))
678 (while (looking-at ":\\([0-7]+\\) \\([0-7]+\\) [0-9A-Fa-f]\\{40\\} [0-9A-Fa-f]\\{40\\} ")
679 (let ((old-perm (string-to-number (match-string 1) 8))
680 (new-perm (string-to-number (match-string 2) 8)))
681 (goto-char (match-end 0))
684 "\\([CR]\\)\\([0-9]*\\)\0\\([^\0]*\\)\0\\([^\0]*\\)\0")
685 (let* ((patch-status (stgit-patch->status patch))
686 (file-subexp (if (eq patch-status 'unapplied)
689 (file (match-string file-subexp)))
694 :cr-score (string-to-number (match-string 2))
695 :cr-from (match-string 3)
696 :cr-to (match-string 4)
697 :status (stgit-file-status-code
700 ((looking-at "\\([ABD-QS-Z]\\)\0\\([^\0]*\\)\0")
708 :status (stgit-file-status-code
710 :file (match-string 2))))))
711 (goto-char (match-end 0))
712 (funcall callback file)))))
715 (defun stgit-insert-patch-files (patch)
716 "Expand (show modification of) the patch PATCH after the line
718 (let* ((patchsym (stgit-patch->name patch))
720 (args (list "-z" (stgit-find-copies-harder-diff-arg)))
721 (ewoc (ewoc-create #'stgit-file-pp nil nil t)))
722 (set-marker-insertion-type end t)
723 (setf (stgit-patch->files-ewoc patch) ewoc)
725 (let ((standard-output (current-buffer)))
726 (apply 'stgit-run-git
727 (cond ((eq patchsym :work)
728 `("diff-files" "-0" ,@args))
729 ((eq patchsym :index)
730 `("diff-index" ,@args "--cached" "HEAD"))
732 `("diff-tree" ,@args "-r" ,(stgit-id patchsym)))))
734 (when (and (eq patchsym :work))
735 (when stgit-show-ignored
736 (stgit-insert-ls-files '("--ignored" "--others") "I"))
737 (when stgit-show-unknown
738 (stgit-insert-ls-files '("--directory" "--no-empty-directory"
741 (sort-regexp-fields nil ":[^\0]*\0\\([^\0]*\\)\0" "\\1"
742 (point-min) (point-max)))
744 (stgit-process-files (lambda (file) (ewoc-enter-last ewoc file)))
746 (unless (ewoc-nth ewoc 0)
749 (propertize "<no files>"
750 'face 'stgit-description-face)
754 (defun stgit-find-file (&optional other-window)
755 (let* ((file (or (stgit-patched-file-at-point)
756 (error "No file at point")))
757 (filename (expand-file-name (stgit-file->file file))))
758 (unless (file-exists-p filename)
759 (error "File does not exist"))
760 (funcall (if other-window 'find-file-other-window 'find-file)
762 (when (eq (stgit-file->status file) 'unmerged)
765 (defun stgit-expand (&optional patches collapse)
766 "Show the contents of marked patches, or the patch at point.
768 See also `stgit-collapse'.
770 Non-interactively, operate on PATCHES, and collapse instead of
771 expand if COLLAPSE is not nil."
772 (interactive (list (stgit-patches-marked-or-at-point t)))
774 (let ((patches-diff (funcall (if collapse #'intersection #'set-difference)
775 patches stgit-expanded-patches)))
776 (setq stgit-expanded-patches
778 (set-difference stgit-expanded-patches patches-diff)
779 (append stgit-expanded-patches patches-diff)))
780 (ewoc-map #'(lambda (patch)
781 (memq (stgit-patch->name patch) patches-diff))
783 (move-to-column (stgit-goal-column)))
785 (defun stgit-collapse (&optional patches)
786 "Hide the contents of marked patches, or the patch at point.
788 See also `stgit-expand'."
789 (interactive (list (stgit-patches-marked-or-at-point t)))
791 (stgit-expand patches t))
793 (defun stgit-select-patch ()
794 (let ((patchname (stgit-patch-name-at-point)))
795 (stgit-expand (list patchname)
796 (memq patchname stgit-expanded-patches))))
798 (defun stgit-expand-directory (file)
799 (let* ((patch (stgit-patch-at-point))
800 (ewoc (stgit-patch->files-ewoc patch))
801 (node (ewoc-locate ewoc))
802 (filename (stgit-file->file file))
803 (start (make-marker))
808 (set-marker start (point))
809 (set-marker end (point))
810 (set-marker-insertion-type end t))
812 (assert (string-match "/$" filename))
813 ;; remove trailing "/"
814 (setf (stgit-file->file file) (substring filename 0 -1))
815 (ewoc-invalidate ewoc node)
818 (let ((standard-output (current-buffer)))
819 (stgit-insert-ls-files (list "--directory" "--others"
820 "--no-empty-directory" "--"
823 (stgit-process-files (lambda (f)
824 (setq node (ewoc-enter-after ewoc node f))))))
826 (let ((inhibit-read-only t))
827 (put-text-property start end 'patch-data patch))))
829 (defun stgit-select-file ()
830 (let* ((file (or (stgit-patched-file-at-point)
831 (error "No file at point")))
832 (filename (stgit-file->file file)))
833 (if (string-match "/$" filename)
834 (stgit-expand-directory file)
837 (defun stgit-select ()
838 "With point on a patch, toggle showing files in the patch.
840 With point on a file, open the associated file. Opens the target
841 file for (applied) copies and renames."
844 (case (get-text-property (point) 'entry-type)
846 (stgit-select-patch))
850 (error "No patch or file on line"))))
852 (defun stgit-find-file-other-window ()
853 "Open file at point in other window"
858 (defun stgit-find-file-merge ()
859 "Open file at point and merge it using `smerge-ediff'."
866 "Hide the stgit buffer."
871 (defun stgit-git-status ()
872 "Show status using `git-status'."
875 (unless (fboundp 'git-status)
876 (error "The stgit-git-status command requires git-status"))
877 (let ((dir default-directory))
878 (save-selected-window
882 (defun stgit-goal-column ()
883 "Return goal column for the current line"
884 (case (get-text-property (point) 'entry-type)
889 (defun stgit-next-line (&optional arg)
890 "Move cursor vertically down ARG lines"
894 (move-to-column (stgit-goal-column)))
896 (defun stgit-previous-line (&optional arg)
897 "Move cursor vertically up ARG lines"
901 (move-to-column (stgit-goal-column)))
903 (defun stgit-next-patch (&optional arg)
904 "Move cursor down ARG patches."
907 (ewoc-goto-next stgit-ewoc (or arg 1))
908 (move-to-column goal-column))
910 (defun stgit-previous-patch (&optional arg)
911 "Move cursor up ARG patches."
914 (ewoc-goto-prev stgit-ewoc (or arg 1))
915 (move-to-column goal-column))
917 (defvar stgit-mode-hook nil
918 "Run after `stgit-mode' is setup.")
920 (defvar stgit-mode-map nil
921 "Keymap for StGit major mode.")
923 (unless stgit-mode-map
924 (let ((diff-map (make-sparse-keymap))
925 (toggle-map (make-sparse-keymap)))
926 (suppress-keymap diff-map)
927 (mapc (lambda (arg) (define-key diff-map (car arg) (cdr arg)))
928 '(("b" . stgit-diff-base)
929 ("c" . stgit-diff-combined)
930 ("m" . stgit-find-file-merge)
931 ("o" . stgit-diff-ours)
932 ("t" . stgit-diff-theirs)))
933 (suppress-keymap toggle-map)
934 (mapc (lambda (arg) (define-key toggle-map (car arg) (cdr arg)))
935 '(("n" . stgit-toggle-patch-names)
936 ("t" . stgit-toggle-worktree)
937 ("i" . stgit-toggle-ignored)
938 ("u" . stgit-toggle-unknown)))
939 (setq stgit-mode-map (make-keymap))
940 (suppress-keymap stgit-mode-map)
941 (mapc (lambda (arg) (define-key stgit-mode-map (car arg) (cdr arg)))
942 `((" " . stgit-mark-down)
943 ("m" . stgit-mark-down)
944 ("\d" . stgit-unmark-up)
945 ("u" . stgit-unmark-down)
948 ("\C-p" . stgit-previous-line)
949 ("\C-n" . stgit-next-line)
950 ([up] . stgit-previous-line)
951 ([down] . stgit-next-line)
952 ("p" . stgit-previous-patch)
953 ("n" . stgit-next-patch)
954 ("\M-{" . stgit-previous-patch)
955 ("\M-}" . stgit-next-patch)
956 ("s" . stgit-git-status)
957 ("g" . stgit-reload-or-repair)
958 ("r" . stgit-refresh)
959 ("\C-c\C-r" . stgit-rename)
961 ("M" . stgit-move-patches)
964 ("c" . stgit-new-and-refresh)
965 ("\C-c\C-c" . stgit-commit)
966 ("\C-c\C-u" . stgit-uncommit)
968 ("R" . stgit-resolve-file)
969 ("\r" . stgit-select)
971 ("-" . stgit-collapse)
972 ("o" . stgit-find-file-other-window)
973 ("i" . stgit-toggle-index)
974 (">" . stgit-push-next)
975 ("<" . stgit-pop-next)
976 ("P" . stgit-push-or-pop)
980 ([?\C-/] . stgit-undo)
981 ("\C-_" . stgit-undo)
982 ([?\C-c ?\C-/] . stgit-redo)
983 ("\C-c\C-_" . stgit-redo)
985 ("\C-c\C-b" . stgit-rebase)
988 ("q" . stgit-quit))))
990 (let ((at-unmerged-file '(let ((file (stgit-patched-file-at-point)))
991 (and file (eq (stgit-file->status file)
993 (patch-collapsed-p '(lambda (p) (not (memq p stgit-expanded-patches)))))
994 (easy-menu-define stgit-menu stgit-mode-map
997 ["Reload" stgit-reload-or-repair
998 :help "Reload StGit status from disk"]
999 ["Repair" stgit-repair
1000 :keys "\\[universal-argument] \\[stgit-reload-or-repair]"
1001 :help "Repair StGit metadata"]
1003 ["Undo" stgit-undo t]
1004 ["Redo" stgit-redo t]
1006 ["Git status" stgit-git-status :active (fboundp 'git-status)]
1008 ["New patch" stgit-new-and-refresh
1009 :help "Create a new patch from changes in index or work tree"
1010 :active (not (and (stgit-index-empty-p) (stgit-work-tree-empty-p)))]
1011 ["New empty patch" stgit-new
1012 :help "Create a new, empty patch"]
1013 ["(Un)mark patch" stgit-toggle-mark
1014 :label (if (memq (stgit-patch-name-at-point nil t)
1015 stgit-marked-patches)
1016 "Unmark patch" "Mark patch")
1017 :active (stgit-patch-name-at-point nil t)]
1018 ["Expand/collapse patch"
1019 (let ((patches (stgit-patches-marked-or-at-point)))
1020 (if (member-if ,patch-collapsed-p patches)
1021 (stgit-expand patches)
1022 (stgit-collapse patches)))
1023 :label (if (member-if ,patch-collapsed-p
1024 (stgit-patches-marked-or-at-point))
1027 :active (stgit-patches-marked-or-at-point)]
1028 ["Edit patch" stgit-edit
1029 :help "Edit patch comment"
1030 :active (stgit-patch-name-at-point nil t)]
1031 ["Rename patch" stgit-rename :active (stgit-patch-name-at-point nil t)]
1032 ["Push/pop patch" stgit-push-or-pop
1033 :label (if (subsetp (stgit-patches-marked-or-at-point nil t)
1034 (stgit-applied-patchsyms t))
1035 "Pop patches" "Push patches")]
1036 ["Delete patches" stgit-delete
1037 :active (stgit-patches-marked-or-at-point nil t)]
1039 ["Move patches" stgit-move-patches
1040 :active stgit-marked-patches
1041 :help "Move marked patch(es) to point"]
1042 ["Squash patches" stgit-squash
1043 :active (> (length stgit-marked-patches) 1)
1044 :help "Merge marked patches into one"]
1046 ["Refresh top patch" stgit-refresh
1047 :active (not (and (stgit-index-empty-p) (stgit-work-tree-empty-p)))
1048 :help "Refresh the top patch with changes in index or work tree"]
1049 ["Refresh this patch" (stgit-refresh t)
1050 :keys "\\[universal-argument] \\[stgit-refresh]"
1051 :help "Refresh marked patch with changes in index or work tree"
1052 :active (and (not (and (stgit-index-empty-p)
1053 (stgit-work-tree-empty-p)))
1054 (stgit-patch-name-at-point nil t))]
1056 ["Find file" stgit-select
1057 :active (eq (get-text-property (point) 'entry-type) 'file)]
1058 ["Open file" stgit-find-file-other-window
1059 :active (eq (get-text-property (point) 'entry-type) 'file)]
1060 ["Toggle file index" stgit-toggle-index
1061 :active (and (eq (get-text-property (point) 'entry-type) 'file)
1062 (memq (stgit-patch-name-at-point) '(:work :index)))
1063 :label (if (eq (stgit-patch-name-at-point) :work)
1064 "Move change to index"
1065 "Move change to work tree")]
1067 ["Show diff" stgit-diff
1068 :active (get-text-property (point) 'entry-type)]
1070 :active (stgit-git-index-unmerged-p)
1071 ["Combined diff" stgit-diff-combined
1072 :active (memq (stgit-patch-name-at-point nil nil) '(:work :index))]
1073 ["Diff against base" stgit-diff-base
1074 :help "Show diff against the common base"
1075 :active (memq (stgit-patch-name-at-point nil nil) '(:work :index))]
1076 ["Diff against ours" stgit-diff-ours
1077 :help "Show diff against our branch"
1078 :active (memq (stgit-patch-name-at-point nil nil) '(:work :index))]
1079 ["Diff against theirs" stgit-diff-theirs
1080 :help "Show diff against their branch"
1081 :active (memq (stgit-patch-name-at-point nil nil) '(:work :index))]
1083 ["Interactive merge" stgit-find-file-merge
1084 :help "Interactively merge the file"
1085 :active ,at-unmerged-file]
1086 ["Resolve file" stgit-resolve-file
1087 :help "Mark file conflict as resolved"
1088 :active ,at-unmerged-file]
1091 ["Show index & work tree" stgit-toggle-worktree :style toggle
1092 :selected stgit-show-worktree]
1093 ["Show unknown files" stgit-toggle-unknown :style toggle
1094 :selected stgit-show-unknown :active stgit-show-worktree]
1095 ["Show ignored files" stgit-toggle-ignored :style toggle
1096 :selected stgit-show-ignored :active stgit-show-worktree]
1097 ["Show patch names" stgit-toggle-patch-names :style toggle
1098 :selected stgit-show-patch-names]
1100 ["Switch branches" stgit-branch t
1101 :help "Switch to or create another branch"]
1102 ["Rebase branch" stgit-rebase t
1103 :help "Rebase the current branch"]
1106 ;; disable tool bar editing buttons
1107 (put 'stgit-mode 'mode-class 'special)
1109 (defun stgit-mode ()
1110 "Major mode for interacting with StGit.
1112 Start StGit using \\[stgit].
1116 \\[stgit-help] Show this help text
1117 \\[stgit-quit] Hide the StGit buffer
1118 \\[describe-bindings] Show all key bindings
1120 \\[stgit-reload-or-repair] Reload the StGit buffer
1121 \\[universal-argument] \\[stgit-reload-or-repair] Repair StGit metadata
1123 \\[stgit-undo] Undo most recent StGit operation
1124 \\[stgit-redo] Undo recent undo
1126 \\[stgit-git-status] Run `git-status' (if available)
1129 \\[stgit-previous-line] Move to previous line
1130 \\[stgit-next-line] Move to next line
1131 \\[stgit-previous-patch] Move to previous patch
1132 \\[stgit-next-patch] Move to next patch
1134 \\[stgit-mark-down] Mark patch and move down
1135 \\[stgit-unmark-up] Unmark patch and move up
1136 \\[stgit-unmark-down] Unmark patch and move down
1138 Commands for patches:
1139 \\[stgit-select] Toggle showing changed files in patch
1140 \\[stgit-refresh] Refresh patch with changes in index or work tree
1141 \\[stgit-diff] Show the patch log and diff
1143 \\[stgit-expand] Show changes in marked patches
1144 \\[stgit-collapse] Hide changes in marked patches
1146 \\[stgit-new-and-refresh] Create a new patch from index or work tree
1147 \\[stgit-new] Create a new, empty patch
1149 \\[stgit-rename] Rename patch
1150 \\[stgit-edit] Edit patch description
1151 \\[stgit-delete] Delete patch(es)
1153 \\[stgit-revert] Revert all changes in index or work tree
1154 \\[stgit-toggle-index] Toggle all changes between index and work tree
1156 \\[stgit-push-next] Push next patch onto stack
1157 \\[stgit-pop-next] Pop current patch from stack
1158 \\[stgit-push-or-pop] Push or pop marked patches
1159 \\[stgit-goto] Make patch at point current by popping or pushing
1161 \\[stgit-squash] Squash (meld together) patches
1162 \\[stgit-move-patches] Move marked patches to point
1164 \\[stgit-commit] Commit patch(es)
1165 \\[stgit-uncommit] Uncommit patch(es)
1168 \\[stgit-select] Open the file in this window
1169 \\[stgit-find-file-other-window] Open the file in another window
1170 \\[stgit-diff] Show the file's diff
1172 \\[stgit-toggle-index] Toggle change between index and work tree
1173 \\[stgit-revert] Revert changes to file
1176 \\[stgit-toggle-patch-names] Toggle showing patch names
1177 \\[stgit-toggle-worktree] Toggle showing index and work tree
1178 \\[stgit-toggle-unknown] Toggle showing unknown files
1179 \\[stgit-toggle-ignored] Toggle showing ignored files
1182 \\[stgit-diff] Show diff of patch or file
1183 \\[stgit-diff-base] Show diff against the merge base
1184 \\[stgit-diff-ours] Show diff against our branch
1185 \\[stgit-diff-theirs] Show diff against their branch
1187 With one prefix argument (e.g., \\[universal-argument] \\[stgit-diff]), \
1188 ignore space changes.
1189 With two prefix arguments (e.g., \\[universal-argument] \
1190 \\[universal-argument] \\[stgit-diff]), ignore all space changes.
1192 Commands for merge conflicts:
1193 \\[stgit-find-file-merge] Resolve conflicts using `smerge-ediff'
1194 \\[stgit-resolve-file] Mark unmerged file as resolved
1196 Commands for branches:
1197 \\[stgit-branch] Switch to or create another branch
1198 \\[stgit-rebase] Rebase the current branch
1200 Customization variables:
1201 `stgit-abbreviate-copies-and-renames'
1202 `stgit-default-show-patch-names'
1203 `stgit-default-show-worktree'
1204 `stgit-find-copies-harder'
1205 `stgit-show-worktree-mode'
1207 See also \\[customize-group] for the \"stgit\" group."
1208 (kill-all-local-variables)
1209 (buffer-disable-undo)
1210 (setq mode-name "StGit"
1211 major-mode 'stgit-mode
1213 (use-local-map stgit-mode-map)
1214 (set (make-local-variable 'list-buffers-directory) default-directory)
1215 (set (make-local-variable 'stgit-marked-patches) nil)
1216 (set (make-local-variable 'stgit-expanded-patches) (list :work :index))
1217 (set (make-local-variable 'stgit-show-patch-names)
1218 stgit-default-show-patch-names)
1219 (set (make-local-variable 'stgit-show-worktree) stgit-default-show-worktree)
1220 (set (make-local-variable 'stgit-index-node) nil)
1221 (set (make-local-variable 'stgit-worktree-node) nil)
1222 (set (make-local-variable 'parse-sexp-lookup-properties) t)
1223 (set-variable 'truncate-lines 't)
1224 (add-hook 'after-save-hook 'stgit-update-saved-file)
1225 (run-hooks 'stgit-mode-hook))
1227 (defun stgit-update-saved-file ()
1228 (let* ((file (expand-file-name buffer-file-name))
1229 (dir (file-name-directory file))
1230 (gitdir (condition-case nil (git-get-top-dir dir)
1232 (buffer (and gitdir (stgit-find-buffer gitdir))))
1234 (with-current-buffer buffer
1235 (stgit-refresh-worktree)))))
1237 (defun stgit-add-mark (patchsym)
1238 "Mark the patch PATCHSYM."
1239 (setq stgit-marked-patches (cons patchsym stgit-marked-patches)))
1241 (defun stgit-remove-mark (patchsym)
1242 "Unmark the patch PATCHSYM."
1243 (setq stgit-marked-patches (delq patchsym stgit-marked-patches)))
1245 (defun stgit-clear-marks ()
1246 "Unmark all patches."
1247 (setq stgit-marked-patches '()))
1249 (defun stgit-patch-at-point (&optional cause-error)
1250 (get-text-property (point) 'patch-data))
1252 (defun stgit-patch-name-at-point (&optional cause-error only-patches)
1253 "Return the patch name on the current line as a symbol.
1254 If CAUSE-ERROR is not nil, signal an error if none found.
1255 If ONLY-PATCHES is not nil, only allow real patches, and not
1256 index or work tree."
1257 (let ((patch (stgit-patch-at-point)))
1260 (memq (stgit-patch->status patch) '(work index))
1263 (stgit-patch->name patch))
1265 (error "No patch on this line")))))
1267 (defun stgit-patched-file-at-point ()
1268 (get-text-property (point) 'file-data))
1270 (defun stgit-patches-marked-or-at-point (&optional cause-error only-patches)
1271 "Return the symbols of the marked patches, or the patch on the current line.
1272 If CAUSE-ERRROR is not nil, signal an error if none found.
1273 If ONLY-PATCHES is not nil, do not include index or work tree."
1274 (if stgit-marked-patches
1275 stgit-marked-patches
1276 (let ((patch (stgit-patch-name-at-point nil only-patches)))
1277 (cond (patch (list patch))
1278 (cause-error (error "No patches marked or at this line"))
1281 (defun stgit-goto-patch (patchsym &optional file)
1282 "Move point to the line containing patch PATCHSYM.
1283 If that patch cannot be found, do nothing.
1285 If the patch was found and FILE is not nil, instead move to that
1286 file's line. If FILE cannot be found, stay on the line of
1288 (let ((node (ewoc-nth stgit-ewoc 0)))
1289 (while (and node (not (eq (stgit-patch->name (ewoc-data node))
1291 (setq node (ewoc-next stgit-ewoc node)))
1292 (when (and node file)
1293 (let* ((file-ewoc (stgit-patch->files-ewoc (ewoc-data node)))
1294 (file-node (ewoc-nth file-ewoc 0)))
1295 (while (and file-node (not (equal (stgit-file->file (ewoc-data file-node)) file)))
1296 (setq file-node (ewoc-next file-ewoc file-node)))
1298 (ewoc-goto-node file-ewoc file-node)
1299 (move-to-column (stgit-goal-column))
1302 (ewoc-goto-node stgit-ewoc node)
1303 (move-to-column goal-column))))
1305 (defun stgit-init ()
1309 (stgit-capture-output nil
1313 (defun stgit-toggle-mark ()
1314 "Toggle mark on the patch under point."
1317 (if (memq (stgit-patch-name-at-point t t) stgit-marked-patches)
1321 (defun stgit-mark ()
1322 "Mark the patch under point."
1325 (let* ((node (ewoc-locate stgit-ewoc))
1326 (patch (ewoc-data node))
1327 (name (stgit-patch->name patch)))
1328 (when (eq name :work)
1329 (error "Cannot mark the work tree"))
1330 (when (eq name :index)
1331 (error "Cannot mark the index"))
1332 (stgit-add-mark (stgit-patch->name patch))
1333 (let ((column (current-column)))
1334 (ewoc-invalidate stgit-ewoc node)
1335 (move-to-column column))))
1337 (defun stgit-mark-down ()
1338 "Mark the patch under point and move to the next patch."
1343 (defun stgit-unmark ()
1344 "Remove mark from the patch on the current line."
1347 (let* ((node (ewoc-locate stgit-ewoc))
1348 (patch (ewoc-data node)))
1349 (stgit-remove-mark (stgit-patch->name patch))
1350 (let ((column (current-column)))
1351 (ewoc-invalidate stgit-ewoc node)
1352 (move-to-column column))))
1354 (defun stgit-unmark-up ()
1355 "Remove mark from the patch on the previous line."
1358 (stgit-previous-patch)
1361 (defun stgit-unmark-down ()
1362 "Remove mark from the patch on the current line."
1368 (defun stgit-rename (name)
1369 "Rename the patch under point to NAME."
1371 (read-string "Patch name: "
1372 (symbol-name (stgit-patch-name-at-point t t)))))
1374 (let ((old-patchsym (stgit-patch-name-at-point t t)))
1375 (stgit-capture-output nil
1376 (stgit-run "rename" old-patchsym name))
1377 (let ((name-sym (intern name)))
1378 (when (memq old-patchsym stgit-expanded-patches)
1379 (setq stgit-expanded-patches
1380 (cons name-sym (delq old-patchsym stgit-expanded-patches))))
1381 (when (memq old-patchsym stgit-marked-patches)
1382 (setq stgit-marked-patches
1383 (cons name-sym (delq old-patchsym stgit-marked-patches))))
1385 (stgit-goto-patch name-sym))))
1387 (defun stgit-reload-or-repair (repair)
1388 "Update the contents of the StGit buffer (`stgit-reload').
1390 With a prefix argument, repair the StGit metadata if the branch
1391 was modified with git commands (`stgit-repair')."
1398 (defun stgit-repair ()
1402 (stgit-capture-output nil
1403 (stgit-run "repair"))
1406 (defun stgit-available-branches (&optional all)
1407 "Returns a list of the names of the available stg branches as strings.
1409 If ALL is not nil, also return non-stgit branches."
1410 (let ((output (with-output-to-string
1411 (stgit-run "branch" "--list")))
1412 (pattern (format "^>?\\s-+%c\\s-+\\(\\S-+\\)"
1416 (while (string-match pattern output start)
1417 (setq result (cons (match-string 1 output) result))
1418 (setq start (match-end 0)))
1421 (defun stgit-branch (branch)
1422 "Switch to or create branch BRANCH."
1423 (interactive (list (completing-read "Switch to branch: "
1424 (stgit-available-branches))))
1426 (when (cond ((equal branch (stgit-current-branch))
1427 (error "Branch is already current"))
1428 ((member branch (stgit-available-branches t))
1429 (stgit-capture-output nil (stgit-run "branch" "--" branch))
1431 ((not (string-match stgit-allowed-branch-name-re branch))
1432 (error "Invalid branch name"))
1433 ((yes-or-no-p (format "Create branch \"%s\"? " branch))
1434 (stgit-capture-output nil (stgit-run "branch" "--create" "--"
1439 (defun stgit-available-refs (&optional omit-stgit)
1440 "Returns a list of the available git refs.
1441 If OMIT-STGIT is not nil, filter out \"resf/heads/*.stgit\"."
1442 (let* ((output (with-output-to-string
1443 (stgit-run-git-silent "for-each-ref" "--format=%(refname)"
1444 "refs/tags" "refs/heads"
1446 (result (split-string output "\n" t)))
1448 (if (string-match "^refs/\\(heads\\|tags\\|remotes\\)/" s)
1449 (substring s (match-end 0))
1452 (delete-if (lambda (s)
1453 (string-match "^refs/heads/.*\\.stgit$" s))
1457 (defun stgit-rebase (new-base)
1458 "Rebase to NEW-BASE."
1459 (interactive (list (completing-read "Rebase to: "
1460 (stgit-available-refs t))))
1462 (stgit-capture-output nil (stgit-run "rebase" new-base))
1465 (defun stgit-commit (count)
1466 "Run stg commit on COUNT commits.
1467 Interactively, the prefix argument is used as COUNT.
1468 A negative COUNT will uncommit instead."
1472 (stgit-uncommit (- count))
1473 (stgit-capture-output nil (stgit-run "commit" "-n" count))
1476 (defun stgit-uncommit (count)
1477 "Run stg uncommit on COUNT commits.
1478 Interactively, the prefix argument is used as COUNT.
1479 A negative COUNT will commit instead."
1483 (stgit-commit (- count))
1484 (stgit-capture-output nil (stgit-run "uncommit" "-n" count))
1487 (defun stgit-neighbour-file ()
1488 "Return the file name of the next file after point, or the
1489 previous file if point is at the last file within a patch."
1490 (let ((old-point (point))
1492 (and (zerop (forward-line 1))
1493 (let ((f (stgit-patched-file-at-point)))
1494 (and f (setq neighbour-file (stgit-file->file f)))))
1495 (goto-char old-point)
1496 (unless neighbour-file
1497 (and (zerop (forward-line -1))
1498 (let ((f (stgit-patched-file-at-point)))
1499 (and f (setq neighbour-file (stgit-file->file f)))))
1500 (goto-char old-point))
1503 (defun stgit-revert-file ()
1504 "Revert the file at point, which must be in the index or the
1508 (let* ((patched-file (or (stgit-patched-file-at-point)
1509 (error "No file on the current line")))
1510 (patch-name (stgit-patch-name-at-point))
1511 (file-status (stgit-file->status patched-file))
1512 (rm-file (cond ((stgit-file->copy-or-rename patched-file)
1513 (stgit-file->cr-to patched-file))
1514 ((eq file-status 'add)
1515 (stgit-file->file patched-file))))
1516 (co-file (cond ((eq file-status 'rename)
1517 (stgit-file->cr-from patched-file))
1518 ((not (memq file-status '(copy add)))
1519 (stgit-file->file patched-file))))
1520 (next-file (stgit-neighbour-file)))
1522 (unless (memq patch-name '(:work :index))
1523 (error "No index or working tree file on this line"))
1525 (when (eq file-status 'ignore)
1526 (error "Cannot revert ignored files"))
1528 (when (eq file-status 'unknown)
1529 (error "Cannot revert unknown files"))
1531 (let ((nfiles (+ (if rm-file 1 0) (if co-file 1 0))))
1532 (when (yes-or-no-p (format "Revert %d file%s? "
1534 (if (= nfiles 1) "" "s")))
1535 (stgit-capture-output nil
1537 (stgit-run-git "rm" "-f" "-q" "--" rm-file))
1539 (stgit-run-git "checkout" "HEAD" co-file)))
1541 (stgit-goto-patch patch-name next-file)))))
1543 (defun stgit-revert ()
1544 "Revert the change at point, which must be the index, the work
1545 tree, or a single change in either."
1548 (let ((patched-file (stgit-patched-file-at-point)))
1551 (let* ((patch-name (or (stgit-patch-name-at-point)
1552 (error "No patch or file at point")))
1553 (patch-desc (case patch-name
1556 (t (error (substitute-command-keys
1557 "Use \\[stgit-delete] to delete a patch"))))))
1558 (when (if (eq patch-name :work)
1559 (stgit-work-tree-empty-p)
1560 (stgit-index-empty-p))
1561 (error (format "There are no changes in the %s to revert"
1563 (and (eq patch-name :index)
1564 (not (stgit-work-tree-empty-p))
1565 (error "Cannot revert index as work tree contains unstaged changes"))
1567 (when (yes-or-no-p (format "Revert all changes in the %s? "
1569 (if (eq patch-name :index)
1570 (stgit-run-git-silent "reset" "--hard" "-q")
1571 (stgit-run-git-silent "checkout" "--" "."))
1572 (stgit-refresh-index)
1573 (stgit-refresh-worktree)
1574 (stgit-goto-patch patch-name))))))
1576 (defun stgit-resolve-file ()
1577 "Resolve conflict in the file at point."
1580 (let* ((patched-file (stgit-patched-file-at-point))
1581 (patch (stgit-patch-at-point))
1582 (patch-name (and patch (stgit-patch->name patch)))
1583 (status (and patched-file (stgit-file->status patched-file))))
1585 (unless (memq patch-name '(:work :index))
1586 (error "No index or working tree file on this line"))
1588 (unless (eq status 'unmerged)
1589 (error "No conflict to resolve at the current line"))
1591 (stgit-capture-output nil
1592 (stgit-move-change-to-index (stgit-file->file patched-file)))
1596 (defun stgit-push-next (npatches)
1597 "Push the first unapplied patch.
1598 With numeric prefix argument, push that many patches."
1601 (stgit-capture-output nil (stgit-run "push" "-n" npatches))
1603 (stgit-refresh-git-status))
1605 (defun stgit-pop-next (npatches)
1606 "Pop the topmost applied patch.
1607 With numeric prefix argument, pop that many patches."
1610 (stgit-capture-output nil (stgit-run "pop" "-n" npatches))
1612 (stgit-refresh-git-status))
1614 (defun stgit-applied-patches (&optional only-patches)
1615 "Return a list of the applied patches.
1617 If ONLY-PATCHES is not nil, exclude index and work tree."
1618 (let ((states (if only-patches
1620 '(applied top index work)))
1622 (ewoc-map (lambda (patch) (when (memq (stgit-patch->status patch) states)
1623 (setq result (cons patch result))))
1627 (defun stgit-applied-patchsyms (&optional only-patches)
1628 "Return a list of the symbols of the applied patches.
1630 If ONLY-PATCHES is not nil, exclude index and work tree."
1631 (mapcar #'stgit-patch->name (stgit-applied-patches only-patches)))
1633 (defun stgit-push-or-pop ()
1634 "Push or pop the marked patches."
1637 (let* ((patchsyms (stgit-patches-marked-or-at-point t t))
1638 (applied-syms (stgit-applied-patchsyms t))
1639 (unapplied (set-difference patchsyms applied-syms)))
1640 (stgit-capture-output nil
1642 (if unapplied "push" "pop")
1644 (stgit-sort-patches (if unapplied unapplied patchsyms)))))
1647 (defun stgit-goto ()
1648 "Go to the patch on the current line.
1650 Pops or pushes patches to make this patch topmost."
1653 (let ((patchsym (stgit-patch-name-at-point t)))
1654 (stgit-capture-output nil
1655 (stgit-run "goto" patchsym))
1658 (defun stgit-id (patchsym)
1659 "Return the git commit id for PATCHSYM.
1660 If PATCHSYM is a keyword, returns PATCHSYM unmodified."
1661 (if (keywordp patchsym)
1663 (let ((result (with-output-to-string
1664 (stgit-run-silent "id" patchsym))))
1665 (unless (string-match "^\\([0-9A-Fa-f]\\{40\\}\\)$" result)
1666 (error "Cannot find commit id for %s" patchsym))
1667 (match-string 1 result))))
1669 (defun stgit-show-patch (unmerged-stage ignore-whitespace)
1670 "Show the patch on the current line.
1672 UNMERGED-STAGE is the argument to `git-diff' that that selects
1673 which stage to diff against in the case of unmerged files."
1674 (let ((space-arg (when (numberp ignore-whitespace)
1675 (cond ((> ignore-whitespace 4)
1676 "--ignore-all-space")
1677 ((> ignore-whitespace 1)
1678 "--ignore-space-change"))))
1679 (patch-name (stgit-patch-name-at-point t)))
1680 (stgit-capture-output "*StGit patch*"
1681 (case (get-text-property (point) 'entry-type)
1683 (let* ((patched-file (stgit-patched-file-at-point))
1684 (patch-id (let ((id (stgit-id patch-name)))
1685 (if (and (eq id :index)
1686 (eq (stgit-file->status patched-file)
1690 (args (append (and space-arg (list space-arg))
1691 (and (stgit-file->cr-from patched-file)
1692 (list (stgit-find-copies-harder-diff-arg)))
1693 (cond ((eq patch-id :index)
1695 ((eq patch-id :work)
1696 (list unmerged-stage))
1698 (list (concat patch-id "^") patch-id)))
1700 (if (stgit-file->copy-or-rename patched-file)
1701 (list (stgit-file->cr-from patched-file)
1702 (stgit-file->cr-to patched-file))
1703 (list (stgit-file->file patched-file))))))
1704 (apply 'stgit-run-git "diff" args)))
1706 (let* ((patch-id (stgit-id patch-name)))
1707 (if (or (eq patch-id :index) (eq patch-id :work))
1708 (apply 'stgit-run-git "diff"
1709 (stgit-find-copies-harder-diff-arg)
1710 (append (and space-arg (list space-arg))
1711 (if (eq patch-id :index)
1713 (list unmerged-stage))))
1714 (let ((args (append '("show" "-O" "--patch-with-stat" "-O" "-M")
1715 (and space-arg (list "-O" space-arg))
1716 (list (stgit-patch-name-at-point)))))
1717 (apply 'stgit-run args)))))
1719 (error "No patch or file at point")))
1720 (with-current-buffer standard-output
1721 (goto-char (point-min))
1724 (defmacro stgit-define-diff (name diff-arg &optional unmerged-action)
1725 `(defun ,name (&optional ignore-whitespace)
1726 ,(format "Show the patch on the current line.
1728 %sWith a prefix argument, ignore whitespace. With a prefix argument
1729 greater than four (e.g., \\[universal-argument] \
1730 \\[universal-argument] \\[%s]), ignore all whitespace."
1732 (format "For unmerged files, %s.\n\n" unmerged-action)
1737 (stgit-show-patch ,diff-arg ignore-whitespace)))
1739 (stgit-define-diff stgit-diff
1741 (stgit-define-diff stgit-diff-ours
1743 "diff against our branch")
1744 (stgit-define-diff stgit-diff-theirs
1746 "diff against their branch")
1747 (stgit-define-diff stgit-diff-base
1749 "diff against the merge base")
1750 (stgit-define-diff stgit-diff-combined
1752 "show a combined diff")
1754 (defun stgit-move-change-to-index (file &optional force)
1755 "Copies the work tree state of FILE to index, using git add or git rm.
1757 If FORCE is not nil, use --force."
1758 (let ((op (if (or (file-exists-p file) (file-symlink-p file))
1759 '("add") '("rm" "-q"))))
1760 (stgit-capture-output "*git output*"
1761 (apply 'stgit-run-git (append op (and force '("--force"))
1762 '("--") (list file))))))
1764 (defun stgit-remove-change-from-index (file)
1765 "Unstages the change in FILE from the index"
1766 (stgit-capture-output "*git output*"
1767 (stgit-run-git "reset" "-q" "--" file)))
1769 (defun stgit-git-index-unmerged-p ()
1771 (with-output-to-string
1772 (setq result (not (zerop (stgit-run-git-silent "diff-index" "--cached"
1774 "--quiet" "HEAD")))))
1777 (defun stgit-file-toggle-index ()
1778 "Move modified file in or out of the index.
1780 Leaves the point where it is, but moves the mark to where the
1781 file ended up. You can then jump to the file with \
1782 \\[exchange-point-and-mark]."
1785 (let* ((patched-file (or (stgit-patched-file-at-point)
1786 (error "No file on the current line")))
1787 (patched-status (stgit-file->status patched-file)))
1788 (when (eq patched-status 'unmerged)
1789 (error (substitute-command-keys "Use \\[stgit-resolve-file] to move an unmerged file to the index")))
1790 (let* ((patch (stgit-patch-at-point))
1791 (patch-name (stgit-patch->name patch))
1792 (mark-file (if (eq patched-status 'rename)
1793 (stgit-file->cr-to patched-file)
1794 (stgit-file->file patched-file)))
1795 (point-file (if (eq patched-status 'rename)
1796 (stgit-file->cr-from patched-file)
1797 (stgit-neighbour-file))))
1799 (cond ((eq patch-name :work)
1800 (stgit-move-change-to-index (stgit-file->file patched-file)
1801 (eq patched-status 'ignore)))
1802 ((eq patch-name :index)
1803 (stgit-remove-change-from-index (stgit-file->file patched-file)))
1805 (error "Can only move files between working tree and index")))
1806 (stgit-refresh-worktree)
1807 (stgit-refresh-index)
1808 (stgit-goto-patch (if (eq patch-name :index) :work :index) mark-file)
1810 (stgit-goto-patch patch-name point-file))))
1812 (defun stgit-toggle-index ()
1813 "Move change in or out of the index.
1815 Works on index and work tree, as well as files in either.
1817 Leaves the point where it is, but moves the mark to where the
1818 file ended up. You can then jump to the file with \
1819 \\[exchange-point-and-mark]."
1822 (if (stgit-patched-file-at-point)
1823 (stgit-file-toggle-index)
1824 (let ((patch-name (stgit-patch-name-at-point)))
1825 (unless (memq patch-name '(:index :work))
1826 (error "Can only move changes between working tree and index"))
1827 (when (stgit-git-index-unmerged-p)
1828 (error "Resolve unmerged changes with \\[stgit-resolve-file] first"))
1829 (if (if (eq patch-name :index)
1830 (stgit-index-empty-p)
1831 (stgit-work-tree-empty-p))
1832 (message "No changes to be moved")
1833 (stgit-capture-output nil
1834 (if (eq patch-name :work)
1835 (stgit-run-git "add" "--update")
1836 (stgit-run-git "reset" "--mixed" "-q")))
1837 (stgit-refresh-worktree)
1838 (stgit-refresh-index))
1839 (stgit-goto-patch (if (eq patch-name :index) :work :index)))))
1841 (defun stgit-edit ()
1842 "Edit the patch on the current line."
1845 (let ((patchsym (stgit-patch-name-at-point t t))
1846 (edit-buf (get-buffer-create "*StGit edit*"))
1847 (dir default-directory))
1848 (log-edit 'stgit-confirm-edit t nil edit-buf)
1849 (set (make-local-variable 'stgit-edit-patchsym) patchsym)
1850 (setq default-directory dir)
1851 (let ((standard-output edit-buf))
1853 (stgit-run-silent "edit" "--save-template=-" patchsym)))))
1855 (defun stgit-confirm-edit ()
1857 (let ((file (make-temp-file "stgit-edit-")))
1858 (write-region (point-min) (point-max) file)
1859 (stgit-capture-output nil
1860 (stgit-run "edit" "-f" file stgit-edit-patchsym))
1861 (with-current-buffer log-edit-parent-buffer
1864 (defun stgit-new (add-sign &optional refresh)
1865 "Create a new patch.
1866 With a prefix argument, include a \"Signed-off-by:\" line at the
1870 (let ((edit-buf (get-buffer-create "*StGit edit*"))
1871 (dir default-directory))
1872 (log-edit 'stgit-confirm-new t nil edit-buf)
1873 (setq default-directory dir)
1874 (set (make-local-variable 'stgit-refresh-after-new) refresh)
1877 (let ((standard-output (current-buffer)))
1878 (stgit-run-silent "new" "--sign" "--save-template=-"))))))
1880 (defun stgit-confirm-new ()
1882 (let ((file (make-temp-file "stgit-edit-"))
1883 (refresh stgit-refresh-after-new))
1884 (write-region (point-min) (point-max) file)
1885 (stgit-capture-output nil
1886 (stgit-run "new" "-f" file))
1887 (with-current-buffer log-edit-parent-buffer
1892 (defun stgit-new-and-refresh (add-sign)
1893 "Create a new patch and refresh it with the current changes.
1895 With a prefix argument, include a \"Signed-off-by:\" line at the
1898 This works just like running `stgit-new' followed by `stgit-refresh'."
1901 (stgit-new add-sign t))
1903 (defun stgit-create-patch-name (description)
1904 "Create a patch name from a long description"
1906 (while (> (length description) 0)
1907 (cond ((string-match "\\`[a-zA-Z_-]+" description)
1908 (setq patch (downcase (concat patch
1909 (match-string 0 description))))
1910 (setq description (substring description (match-end 0))))
1911 ((string-match "\\` +" description)
1912 (setq patch (concat patch "-"))
1913 (setq description (substring description (match-end 0))))
1914 ((string-match "\\`[^a-zA-Z_-]+" description)
1915 (setq description (substring description (match-end 0))))))
1916 (cond ((= (length patch) 0)
1918 ((> (length patch) 20)
1919 (substring patch 0 20))
1922 (defun stgit-delete (patchsyms &optional spill-p)
1923 "Delete the patches in PATCHSYMS.
1924 Interactively, delete the marked patches, or the patch at point.
1926 With a prefix argument, or SPILL-P, spill the patch contents to
1927 the work tree and index."
1928 (interactive (list (stgit-patches-marked-or-at-point t t)
1929 current-prefix-arg))
1932 (error "No patches to delete"))
1933 (when (memq :index patchsyms)
1934 (error "Cannot delete the index"))
1935 (when (memq :work patchsyms)
1936 (error "Cannot delete the work tree"))
1938 (let ((npatches (length patchsyms)))
1939 (when (yes-or-no-p (format "Really delete %d patch%s%s? "
1941 (if (= 1 npatches) "" "es")
1943 " (spilling contents to index)"
1945 (let ((args (if spill-p
1946 (cons "--spill" patchsyms)
1948 (stgit-capture-output nil
1949 (apply 'stgit-run "delete" args))
1952 (defun stgit-move-patches-target ()
1953 "Return the patchsym indicating a target patch for
1954 `stgit-move-patches'.
1956 This is either the first unmarked patch at or after point, or one
1957 of :top and :bottom if the point is after or before the applied
1963 (let ((patchsym (stgit-patch-name-at-point)))
1964 (cond ((memq patchsym '(:work :index)) (setq result :top))
1965 (patchsym (if (memq patchsym stgit-marked-patches)
1967 (setq result patchsym)))
1968 ((re-search-backward "^>" nil t) (setq result :top))
1969 (t (setq result :bottom)))))
1972 (defun stgit-sort-patches (patchsyms)
1973 "Returns the list of patches in PATCHSYMS sorted according to
1974 their position in the patch series, bottommost first.
1976 PATCHSYMS must not contain duplicate entries."
1977 (let (sorted-patchsyms
1978 (series (with-output-to-string
1979 (with-current-buffer standard-output
1980 (stgit-run-silent "series" "--noprefix"))))
1982 (while (string-match "^\\(.+\\)" series start)
1983 (let ((patchsym (intern (match-string 1 series))))
1984 (when (memq patchsym patchsyms)
1985 (setq sorted-patchsyms (cons patchsym sorted-patchsyms))))
1986 (setq start (match-end 0)))
1987 (setq sorted-patchsyms (nreverse sorted-patchsyms))
1989 (unless (= (length patchsyms) (length sorted-patchsyms))
1990 (error "Internal error"))
1994 (defun stgit-move-patches (patchsyms target-patch)
1995 "Move the patches in PATCHSYMS to below TARGET-PATCH.
1996 If TARGET-PATCH is :bottom or :top, move the patches to the
1997 bottom or top of the stack, respectively.
1999 Interactively, move the marked patches to where the point is."
2000 (interactive (list stgit-marked-patches
2001 (stgit-move-patches-target)))
2004 (error "Need at least one patch to move"))
2006 (unless target-patch
2007 (error "Point not at a patch"))
2009 ;; need to have patchsyms sorted by position in the stack
2010 (let ((sorted-patchsyms (stgit-sort-patches patchsyms)))
2011 (stgit-capture-output nil
2012 (if (eq target-patch :top)
2013 (apply 'stgit-run "float" sorted-patchsyms)
2016 (append (unless (eq target-patch :bottom)
2017 (list "--to" target-patch))
2019 sorted-patchsyms)))))
2022 (defun stgit-squash (patchsyms)
2023 "Squash the patches in PATCHSYMS.
2024 Interactively, squash the marked patches.
2026 Unless there are any conflicts, the patches will be merged into
2027 one patch, which will occupy the same spot in the series as the
2028 deepest patch had before the squash."
2029 (interactive (list stgit-marked-patches))
2031 (when (< (length patchsyms) 2)
2032 (error "Need at least two patches to squash"))
2033 (let ((stgit-buffer (current-buffer))
2034 (edit-buf (get-buffer-create "*StGit edit*"))
2035 (dir default-directory)
2036 (sorted-patchsyms (stgit-sort-patches patchsyms)))
2037 (log-edit 'stgit-confirm-squash t nil edit-buf)
2038 (set (make-local-variable 'stgit-patchsyms) sorted-patchsyms)
2039 (setq default-directory dir)
2040 (let ((result (let ((standard-output edit-buf))
2042 (apply 'stgit-run-silent "squash"
2043 "--save-template=-" sorted-patchsyms)))))
2045 ;; stg squash may have reordered the patches or caused conflicts
2046 (with-current-buffer stgit-buffer
2049 (unless (eq 0 result)
2051 (rename-buffer "*StGit error*")
2052 (resize-temp-buffer-window)
2053 (switch-to-buffer-other-window stgit-buffer)
2054 (error "stg squash failed")))))
2056 (defun stgit-confirm-squash ()
2058 (let ((file (make-temp-file "stgit-edit-")))
2059 (write-region (point-min) (point-max) file)
2060 (stgit-capture-output nil
2061 (apply 'stgit-run "squash" "-f" file stgit-patchsyms))
2062 (with-current-buffer log-edit-parent-buffer
2064 ;; Go to first marked patch and stay there
2065 (goto-char (point-min))
2066 (re-search-forward (concat "^[>+-]\\*") nil t)
2067 (move-to-column goal-column)
2068 (let ((pos (point)))
2072 (defun stgit-help ()
2073 "Display help for the StGit mode."
2075 (describe-function 'stgit-mode))
2077 (defun stgit-undo-or-redo (redo hard)
2078 "Run stg undo or, if REDO is non-nil, stg redo.
2080 If HARD is non-nil, use the --hard flag."
2082 (let ((cmd (if redo "redo" "undo")))
2083 (stgit-capture-output nil
2085 (when (or (and (stgit-index-empty-p)
2086 (stgit-work-tree-empty-p))
2087 (y-or-n-p (format "Hard %s may overwrite index/work tree changes. Continue? "
2089 (stgit-run cmd "--hard"))
2093 (defun stgit-undo (&optional arg)
2095 With prefix argument, run it with the --hard flag.
2097 See also `stgit-redo'."
2099 (stgit-undo-or-redo nil arg))
2101 (defun stgit-redo (&optional arg)
2103 With prefix argument, run it with the --hard flag.
2105 See also `stgit-undo'."
2107 (stgit-undo-or-redo t arg))
2109 (defun stgit-refresh (&optional arg)
2111 If the index contains any changes, only refresh from index.
2113 With prefix argument, refresh the marked patch or the patch under point."
2116 (let ((patchargs (if arg
2117 (let ((patches (stgit-patches-marked-or-at-point nil t)))
2118 (when (> (length patches) 1)
2119 (error "Too many patches marked"))
2120 (cons "-p" patches))
2122 (unless (stgit-index-empty-p)
2123 (setq patchargs (cons "--index" patchargs)))
2124 (stgit-capture-output nil
2125 (apply 'stgit-run "refresh" patchargs))
2126 (stgit-refresh-git-status))
2129 (defvar stgit-show-worktree nil
2130 "If nil, inhibit showing work tree and index in the stgit buffer.
2132 See also `stgit-show-worktree-mode'.")
2134 (defvar stgit-show-ignored nil
2135 "If nil, inhibit showing files ignored by git.")
2137 (defvar stgit-show-unknown nil
2138 "If nil, inhibit showing files not registered with git.")
2140 (defvar stgit-show-patch-names t
2141 "If nil, inhibit showing patch names.")
2143 (defun stgit-toggle-worktree (&optional arg)
2144 "Toggle the visibility of the work tree.
2145 With ARG, show the work tree if ARG is positive.
2147 Its initial setting is controlled by `stgit-default-show-worktree'.
2149 `stgit-show-worktree-mode' controls where on screen the index and
2150 work tree will show up."
2153 (setq stgit-show-worktree
2156 (not stgit-show-worktree)))
2159 (defun stgit-toggle-ignored (&optional arg)
2160 "Toggle the visibility of files ignored by git in the work
2161 tree. With ARG, show these files if ARG is positive.
2163 Use \\[stgit-toggle-worktree] to show the work tree."
2166 (setq stgit-show-ignored
2169 (not stgit-show-ignored)))
2172 (defun stgit-toggle-unknown (&optional arg)
2173 "Toggle the visibility of files not registered with git in the
2174 work tree. With ARG, show these files if ARG is positive.
2176 Use \\[stgit-toggle-worktree] to show the work tree."
2179 (setq stgit-show-unknown
2182 (not stgit-show-unknown)))
2185 (defun stgit-toggle-patch-names (&optional arg)
2186 "Toggle the visibility of patch names. With ARG, show patch names
2189 The initial setting is controlled by `stgit-default-show-patch-names'."
2192 (setq stgit-show-patch-names
2195 (not stgit-show-patch-names)))