0

I would like to have my git timestamps in UTC. Currently attempting to commit using magit gives

Wrong type argument: sequencep, my/magit-timestamp-utc

Here's the code:

(defun timestamp-now()
  (format-time-string "%Y-%m-%dT%H:%M:%S%z" (current-time)))

(defun timestamp-utc ()
  (let* ((original-tz (getenv "TZ")))
    (setenv "TZ" "UTC0")
    (let ((timestamp (timestamp-now)))
      (setenv "TZ" original-tz)
      timestamp)))

(defun my/magit-timestamp-utc (&optional prompt default)
  (concat "--date=" (timestamp-utc)))

(setq magit-commit-popup
  '(:variable magit-commit-arguments
    :man-page "git-commit"
    :switches ((?a "Stage all modified and deleted files"   "--all")
               (?e "Allow empty commit"                     "--allow-empty")
               (?v "Show diff of changes to be committed"   "--verbose")
               (?h "Disable hooks"                          "--no-verify")
               (?s "Add Signed-off-by line"                 "--signoff")
               (?R "Claim authorship and reset author date" "--reset-author")
               (?u "UTC" my/magit-timestamp-utc))
    :options  ((?A "Override the author"  "--author=")
               (?S "Sign using gpg"       "--gpg-sign=" magit-read-gpg-secret-key)
               (?C "Reuse commit message" "--reuse-message="
                   magit-read-reuse-message))
    :actions  ((?c "Commit"         magit-commit)
               (?e "Extend"         magit-commit-extend)
               (?f "Fixup"          magit-commit-fixup)
               (?F "Instant Fixup"  magit-commit-instant-fixup) nil
               (?w "Reword"         magit-commit-reword)
               (?s "Squash"         magit-commit-squash)
               (?S "Instant Squash" magit-commit-instant-squash) nil
               (?a "Amend"          magit-commit-amend)
               (?A "Augment"        magit-commit-augment))
    :max-action-columns 4
    :default-action magit-commit))
0

You can of course just redefine the complete popup but a better way would be to just add a new switch using magit-define-popup-switch as documented in the manual.

Regardless of how you define it, a switch's third part has to be a constant string, the name of the switch (when using magit-define-popup-switch then that is the argument named switch). In some rare cases a switch has the form --arg=val like you are trying to do here, but it still has to be a constant string, not (the name of) a function that returns such a string.

The optional forth part of an option can be a function. However that function is only called when you invoke the option and is supposed to then read a value in the minibuffer. Automatically generating a value for an option every time the popup is invoked is not supported.

To achieve what you want you have to advice magit-commit-create and likely a few other magit-commit-* commands.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.