Signed-off-by: Gustav Hållberg <gustav@virtutech.com>
(switch-to-stgit-buffer (git-get-top-dir dir))
(stgit-reload))
(switch-to-stgit-buffer (git-get-top-dir dir))
(stgit-reload))
+(defun stgit-assert-mode ()
+ "Signal an error if not in an StGit buffer."
+ (assert (derived-mode-p 'stgit-mode) nil "Not an StGit buffer"))
+
(unless (fboundp 'git-get-top-dir)
(defun git-get-top-dir (dir)
"Retrieve the top-level directory of a git tree."
(unless (fboundp 'git-get-top-dir)
(defun git-get-top-dir (dir)
"Retrieve the top-level directory of a git tree."
(defun stgit-reload ()
"Update the contents of the StGit buffer."
(interactive)
(defun stgit-reload ()
"Update the contents of the StGit buffer."
(interactive)
(let ((inhibit-read-only t)
(curline (line-number-at-pos))
(curpatch (stgit-patch-name-at-point))
(let ((inhibit-read-only t)
(curline (line-number-at-pos))
(curpatch (stgit-patch-name-at-point))
Non-interactively, operate on PATCHES, and collapse instead of
expand if COLLAPSE is not nil."
(interactive (list (stgit-patches-marked-or-at-point)))
Non-interactively, operate on PATCHES, and collapse instead of
expand if COLLAPSE is not nil."
(interactive (list (stgit-patches-marked-or-at-point)))
(let ((patches-diff (funcall (if collapse #'intersection #'set-difference)
patches stgit-expanded-patches)))
(setq stgit-expanded-patches
(let ((patches-diff (funcall (if collapse #'intersection #'set-difference)
patches stgit-expanded-patches)))
(setq stgit-expanded-patches
See also `stgit-expand'."
(interactive (list (stgit-patches-marked-or-at-point)))
See also `stgit-expand'."
(interactive (list (stgit-patches-marked-or-at-point)))
(stgit-expand patches t))
(defun stgit-select-patch ()
(stgit-expand patches t))
(defun stgit-select-patch ()
With point on a file, open the associated file. Opens the target
file for (applied) copies and renames."
(interactive)
With point on a file, open the associated file. Opens the target
file for (applied) copies and renames."
(interactive)
(case (get-text-property (point) 'entry-type)
('patch
(stgit-select-patch))
(case (get-text-property (point) 'entry-type)
('patch
(stgit-select-patch))
(defun stgit-find-file-other-window ()
"Open file at point in other window"
(interactive)
(defun stgit-find-file-other-window ()
"Open file at point in other window"
(interactive)
(stgit-find-file t))
(defun stgit-find-file-merge ()
"Open file at point and merge it using `smerge-ediff'."
(interactive)
(stgit-find-file t))
(defun stgit-find-file-merge ()
"Open file at point and merge it using `smerge-ediff'."
(interactive)
(stgit-find-file t)
(smerge-ediff))
(defun stgit-quit ()
"Hide the stgit buffer."
(interactive)
(stgit-find-file t)
(smerge-ediff))
(defun stgit-quit ()
"Hide the stgit buffer."
(interactive)
(bury-buffer))
(defun stgit-git-status ()
"Show status using `git-status'."
(interactive)
(bury-buffer))
(defun stgit-git-status ()
"Show status using `git-status'."
(interactive)
(unless (fboundp 'git-status)
(error "The stgit-git-status command requires git-status"))
(let ((dir default-directory))
(unless (fboundp 'git-status)
(error "The stgit-git-status command requires git-status"))
(let ((dir default-directory))
(defun stgit-next-line (&optional arg)
"Move cursor vertically down ARG lines"
(interactive "p")
(defun stgit-next-line (&optional arg)
"Move cursor vertically down ARG lines"
(interactive "p")
(next-line arg)
(move-to-column (stgit-goal-column)))
(defun stgit-previous-line (&optional arg)
"Move cursor vertically up ARG lines"
(interactive "p")
(next-line arg)
(move-to-column (stgit-goal-column)))
(defun stgit-previous-line (&optional arg)
"Move cursor vertically up ARG lines"
(interactive "p")
(previous-line arg)
(move-to-column (stgit-goal-column)))
(defun stgit-next-patch (&optional arg)
"Move cursor down ARG patches."
(interactive "p")
(previous-line arg)
(move-to-column (stgit-goal-column)))
(defun stgit-next-patch (&optional arg)
"Move cursor down ARG patches."
(interactive "p")
(ewoc-goto-next stgit-ewoc (or arg 1))
(move-to-column goal-column))
(defun stgit-previous-patch (&optional arg)
"Move cursor up ARG patches."
(interactive "p")
(ewoc-goto-next stgit-ewoc (or arg 1))
(move-to-column goal-column))
(defun stgit-previous-patch (&optional arg)
"Move cursor up ARG patches."
(interactive "p")
(ewoc-goto-prev stgit-ewoc (or arg 1))
(move-to-column goal-column))
(ewoc-goto-prev stgit-ewoc (or arg 1))
(move-to-column goal-column))
(defun stgit-init ()
"Run stg init."
(interactive)
(defun stgit-init ()
"Run stg init."
(interactive)
(stgit-capture-output nil
(stgit-run "init"))
(stgit-reload))
(stgit-capture-output nil
(stgit-run "init"))
(stgit-reload))
(defun stgit-mark ()
"Mark the patch under point."
(interactive)
(defun stgit-mark ()
"Mark the patch under point."
(interactive)
(let* ((node (ewoc-locate stgit-ewoc))
(patch (ewoc-data node))
(name (stgit-patch-name patch)))
(let* ((node (ewoc-locate stgit-ewoc))
(patch (ewoc-data node))
(name (stgit-patch-name patch)))
(defun stgit-unmark-up ()
"Remove mark from the patch on the previous line."
(interactive)
(defun stgit-unmark-up ()
"Remove mark from the patch on the previous line."
(interactive)
(stgit-previous-patch)
(let* ((node (ewoc-locate stgit-ewoc))
(patch (ewoc-data node)))
(stgit-previous-patch)
(let* ((node (ewoc-locate stgit-ewoc))
(patch (ewoc-data node)))
(defun stgit-unmark-down ()
"Remove mark from the patch on the current line."
(interactive)
(defun stgit-unmark-down ()
"Remove mark from the patch on the current line."
(interactive)
(let* ((node (ewoc-locate stgit-ewoc))
(patch (ewoc-data node)))
(stgit-remove-mark (stgit-patch-name patch))
(let* ((node (ewoc-locate stgit-ewoc))
(patch (ewoc-data node)))
(stgit-remove-mark (stgit-patch-name patch))
(interactive (list
(read-string "Patch name: "
(symbol-name (stgit-patch-name-at-point t t)))))
(interactive (list
(read-string "Patch name: "
(symbol-name (stgit-patch-name-at-point t t)))))
(let ((old-patchsym (stgit-patch-name-at-point t t)))
(stgit-capture-output nil
(stgit-run "rename" old-patchsym name))
(let ((old-patchsym (stgit-patch-name-at-point t t)))
(stgit-capture-output nil
(stgit-run "rename" old-patchsym name))
With a prefix argument, repair the StGit metadata if the branch
was modified with git commands (`stgit-repair')."
(interactive "P")
With a prefix argument, repair the StGit metadata if the branch
was modified with git commands (`stgit-repair')."
(interactive "P")
(if repair
(stgit-repair)
(stgit-reload)))
(if repair
(stgit-repair)
(stgit-reload)))
(defun stgit-repair ()
"Run stg repair."
(interactive)
(defun stgit-repair ()
"Run stg repair."
(interactive)
(stgit-capture-output nil
(stgit-run "repair"))
(stgit-reload))
(stgit-capture-output nil
(stgit-run "repair"))
(stgit-reload))
"Switch to branch BRANCH."
(interactive (list (completing-read "Switch to branch: "
(stgit-available-branches))))
"Switch to branch BRANCH."
(interactive (list (completing-read "Switch to branch: "
(stgit-available-branches))))
(stgit-capture-output nil (stgit-run "branch" "--" branch))
(stgit-reload))
(stgit-capture-output nil (stgit-run "branch" "--" branch))
(stgit-reload))
"Rebase to NEW-BASE."
(interactive (list (completing-read "Rebase to: "
(stgit-available-refs t))))
"Rebase to NEW-BASE."
(interactive (list (completing-read "Rebase to: "
(stgit-available-refs t))))
(stgit-capture-output nil (stgit-run "rebase" new-base))
(stgit-reload))
(stgit-capture-output nil (stgit-run "rebase" new-base))
(stgit-reload))
Interactively, the prefix argument is used as COUNT.
A negative COUNT will uncommit instead."
(interactive "p")
Interactively, the prefix argument is used as COUNT.
A negative COUNT will uncommit instead."
(interactive "p")
(if (< count 0)
(stgit-uncommit (- count))
(stgit-capture-output nil (stgit-run "commit" "-n" count))
(if (< count 0)
(stgit-uncommit (- count))
(stgit-capture-output nil (stgit-run "commit" "-n" count))
Interactively, the prefix argument is used as COUNT.
A negative COUNT will commit instead."
(interactive "p")
Interactively, the prefix argument is used as COUNT.
A negative COUNT will commit instead."
(interactive "p")
(if (< count 0)
(stgit-commit (- count))
(stgit-capture-output nil (stgit-run "uncommit" "-n" count))
(if (< count 0)
(stgit-commit (- count))
(stgit-capture-output nil (stgit-run "uncommit" "-n" count))
"Revert the file at point, which must be in the index or the
working tree."
(interactive)
"Revert the file at point, which must be in the index or the
working tree."
(interactive)
(let* ((patched-file (or (stgit-patched-file-at-point)
(error "No file on the current line")))
(patch-name (stgit-patch-name-at-point))
(let* ((patched-file (or (stgit-patched-file-at-point)
(error "No file on the current line")))
(patch-name (stgit-patch-name-at-point))
"Revert the change at point, which must be the index, the work
tree, or a single change in either."
(interactive)
"Revert the change at point, which must be the index, the work
tree, or a single change in either."
(interactive)
(let ((patched-file (stgit-patched-file-at-point)))
(if patched-file
(stgit-revert-file)
(let ((patched-file (stgit-patched-file-at-point)))
(if patched-file
(stgit-revert-file)
(defun stgit-resolve-file ()
"Resolve conflict in the file at point."
(interactive)
(defun stgit-resolve-file ()
"Resolve conflict in the file at point."
(interactive)
(let* ((patched-file (stgit-patched-file-at-point))
(patch (stgit-patch-at-point))
(patch-name (and patch (stgit-patch-name patch)))
(let* ((patched-file (stgit-patched-file-at-point))
(patch (stgit-patch-at-point))
(patch-name (and patch (stgit-patch-name patch)))
"Push the first unapplied patch.
With numeric prefix argument, push that many patches."
(interactive "p")
"Push the first unapplied patch.
With numeric prefix argument, push that many patches."
(interactive "p")
(stgit-capture-output nil (stgit-run "push" "-n" npatches))
(stgit-reload)
(stgit-refresh-git-status))
(stgit-capture-output nil (stgit-run "push" "-n" npatches))
(stgit-reload)
(stgit-refresh-git-status))
"Pop the topmost applied patch.
With numeric prefix argument, pop that many patches."
(interactive "p")
"Pop the topmost applied patch.
With numeric prefix argument, pop that many patches."
(interactive "p")
(stgit-capture-output nil (stgit-run "pop" "-n" npatches))
(stgit-reload)
(stgit-refresh-git-status))
(stgit-capture-output nil (stgit-run "pop" "-n" npatches))
(stgit-reload)
(stgit-refresh-git-status))
(defun stgit-push-or-pop ()
"Push or pop the patch on the current line."
(interactive)
(defun stgit-push-or-pop ()
"Push or pop the patch on the current line."
(interactive)
(let ((patchsym (stgit-patch-name-at-point t t))
(applied (stgit-applied-at-point-p)))
(stgit-capture-output nil
(let ((patchsym (stgit-patch-name-at-point t t))
(applied (stgit-applied-at-point-p)))
(stgit-capture-output nil
(defun stgit-goto ()
"Go to the patch on the current line."
(interactive)
(defun stgit-goto ()
"Go to the patch on the current line."
(interactive)
(let ((patchsym (stgit-patch-name-at-point t)))
(stgit-capture-output nil
(stgit-run "goto" patchsym))
(let ((patchsym (stgit-patch-name-at-point t)))
(stgit-capture-output nil
(stgit-run "goto" patchsym))
"")
name)
(interactive "p")
"")
name)
(interactive "p")
(stgit-show-patch ,diff-arg ignore-whitespace)))
(stgit-define-diff stgit-diff
(stgit-show-patch ,diff-arg ignore-whitespace)))
(stgit-define-diff stgit-diff
file ended up. You can then jump to the file with \
\\[exchange-point-and-mark]."
(interactive)
file ended up. You can then jump to the file with \
\\[exchange-point-and-mark]."
(interactive)
(let* ((patched-file (or (stgit-patched-file-at-point)
(error "No file on the current line")))
(patched-status (stgit-file-status patched-file)))
(let* ((patched-file (or (stgit-patched-file-at-point)
(error "No file on the current line")))
(patched-status (stgit-file-status patched-file)))
file ended up. You can then jump to the file with \
\\[exchange-point-and-mark]."
(interactive)
file ended up. You can then jump to the file with \
\\[exchange-point-and-mark]."
(interactive)
(if (stgit-patched-file-at-point)
(stgit-file-toggle-index)
(let ((patch-name (stgit-patch-name-at-point)))
(if (stgit-patched-file-at-point)
(stgit-file-toggle-index)
(let ((patch-name (stgit-patch-name-at-point)))
(defun stgit-edit ()
"Edit the patch on the current line."
(interactive)
(defun stgit-edit ()
"Edit the patch on the current line."
(interactive)
(let ((patchsym (stgit-patch-name-at-point t t))
(edit-buf (get-buffer-create "*StGit edit*"))
(dir default-directory))
(let ((patchsym (stgit-patch-name-at-point t t))
(edit-buf (get-buffer-create "*StGit edit*"))
(dir default-directory))
With a prefix argument, include a \"Signed-off-by:\" line at the
end of the patch."
(interactive "P")
With a prefix argument, include a \"Signed-off-by:\" line at the
end of the patch."
(interactive "P")
(let ((edit-buf (get-buffer-create "*StGit edit*"))
(dir default-directory))
(log-edit 'stgit-confirm-new t nil edit-buf)
(let ((edit-buf (get-buffer-create "*StGit edit*"))
(dir default-directory))
(log-edit 'stgit-confirm-new t nil edit-buf)
This works just like running `stgit-new' followed by `stgit-refresh'."
(interactive "P")
This works just like running `stgit-new' followed by `stgit-refresh'."
(interactive "P")
(stgit-new add-sign t))
(defun stgit-create-patch-name (description)
(stgit-new add-sign t))
(defun stgit-create-patch-name (description)
the work tree and index."
(interactive (list (stgit-patches-marked-or-at-point)
current-prefix-arg))
the work tree and index."
(interactive (list (stgit-patches-marked-or-at-point)
current-prefix-arg))
(unless patchsyms
(error "No patches to delete"))
(when (memq :index patchsyms)
(unless patchsyms
(error "No patches to delete"))
(when (memq :index patchsyms)
Interactively, move the marked patches to where the point is."
(interactive (list stgit-marked-patches
(stgit-move-patches-target)))
Interactively, move the marked patches to where the point is."
(interactive (list stgit-marked-patches
(stgit-move-patches-target)))
(unless patchsyms
(error "Need at least one patch to move"))
(unless patchsyms
(error "Need at least one patch to move"))
one patch, which will occupy the same spot in the series as the
deepest patch had before the squash."
(interactive (list stgit-marked-patches))
one patch, which will occupy the same spot in the series as the
deepest patch had before the squash."
(interactive (list stgit-marked-patches))
(when (< (length patchsyms) 2)
(error "Need at least two patches to squash"))
(let ((stgit-buffer (current-buffer))
(when (< (length patchsyms) 2)
(error "Need at least two patches to squash"))
(let ((stgit-buffer (current-buffer))
See also `stgit-redo'."
(interactive "P")
See also `stgit-redo'."
(interactive "P")
(stgit-capture-output nil
(if arg
(stgit-run "undo" "--hard")
(stgit-capture-output nil
(if arg
(stgit-run "undo" "--hard")
See also `stgit-undo'."
(interactive "P")
See also `stgit-undo'."
(interactive "P")
(stgit-capture-output nil
(if arg
(stgit-run "redo" "--hard")
(stgit-capture-output nil
(if arg
(stgit-run "redo" "--hard")
With prefix argument, refresh the marked patch or the patch under point."
(interactive "P")
With prefix argument, refresh the marked patch or the patch under point."
(interactive "P")
(let ((patchargs (if arg
(let ((patches (stgit-patches-marked-or-at-point)))
(cond ((null patches)
(let ((patchargs (if arg
(let ((patches (stgit-patches-marked-or-at-point)))
(cond ((null patches)
`stgit-show-worktree-mode' controls where on screen the index and
work tree will show up."
(interactive)
`stgit-show-worktree-mode' controls where on screen the index and
work tree will show up."
(interactive)
(setq stgit-show-worktree
(if (numberp arg)
(> arg 0)
(setq stgit-show-worktree
(if (numberp arg)
(> arg 0)
Use \\[stgit-toggle-worktree] to show the work tree."
(interactive)
Use \\[stgit-toggle-worktree] to show the work tree."
(interactive)
(setq stgit-show-ignored
(if (numberp arg)
(> arg 0)
(setq stgit-show-ignored
(if (numberp arg)
(> arg 0)
Use \\[stgit-toggle-worktree] to show the work tree."
(interactive)
Use \\[stgit-toggle-worktree] to show the work tree."
(interactive)
(setq stgit-show-unknown
(if (numberp arg)
(> arg 0)
(setq stgit-show-unknown
(if (numberp arg)
(> arg 0)