(defvar cherry-skip-list-file
(expand-file-name "admin/cherry-skip-list" source-directory))
+(defvar cherry-did-fetch nil)
+
+(defvar cherry-upstream-commits nil)
+
(defun cherry--call-git (&rest args)
(apply #'call-process "git" nil nil nil "-C" source-directory args))
t)))
(defun cherry-upstream-commits ()
- (string-lines
- (shell-command-to-string
- (concat "git -C " source-directory
- " cherry HEAD "
- cherry-upstream-remote "/" cherry-upstream-branch
- " | grep -vE '^-' | cut -f 2 -d ' '"))
- t))
-
-(defun cherry-pick-new-commits ()
- "Pick or skip new commits in the upstream branch."
- (interactive)
+ (setq cherry-upstream-commits
+ (or cherry-upstream-commits
+ (string-lines
+ (shell-command-to-string
+ (concat "git -C " source-directory
+ " cherry HEAD "
+ cherry-upstream-remote "/" cherry-upstream-branch
+ " | grep -vE '^-' | cut -f 2 -d ' '"))
+ t))))
+
+(defun cherry-pick-new-commits (&optional force)
+ "Pick or skip new commits in the upstream branch.
+
+With non-nil optional argument FORCE (interactively, the prefix
+argument), force fetching and scanning for upstream commits even if
+already done in this session."
+ (interactive "P")
(message "Ensuring working directory is clean...")
(unless (= 0 (cherry--call-git "diff-index" "--quiet" "HEAD" "--"))
(user-error "Working directory is dirty, cannot start cherry picking"))
- (message "Fetching from upstream...")
- (cherry--call-git "fetch" cherry-upstream-remote)
+ (when force
+ (setq cherry-did-fetch nil
+ cherry-upstream-commits nil))
+ (unless cherry-did-fetch
+ (message "Fetching from upstream...")
+ (cherry--call-git "fetch" cherry-upstream-remote)
+ (setq cherry-did-fetch t))
(message "Listing upstream commits...")
(let ((upstream-commits (cherry-upstream-commits))
(new-commits nil)