Factored out common pattern into toggle-without-config
authorSaba Saba <saba@sabadev.xyz>
Thu, 9 Feb 2023 17:26:21 +0000 (12:26 -0500)
committerSaba Saba <saba@sabadev.xyz>
Thu, 9 Feb 2023 17:26:21 +0000 (12:26 -0500)
git-repl.cl

index 58b36e8..d30907e 100644 (file)
        ,@body
        (pop-config))))
 
+(defmacro toggle-without-config (without-config &body body)
+  `(if ,without-config
+       (without-config-do ,@body)
+       ,@body))
+
 (defun add-quotes (text)
   (format nil "\"~a\"" text))
 
 (defun-public checkout (revision &key (without-config nil))
   "Checks out the specified revision.
   If :without-config is set to T (default is NIL), stashes your configuration before the checkout and pops the stash afterwards."
-  (if without-config
-      (without-config-do
-        (git "checkout" revision))
-      (git "checkout" revision)))
+  (toggle-without-config without-config (git "checkout" revision)))
 
 (defun-public reset-branch (revision &key (mode 'mixed) (without-config nil))
   "Performs a reset to the specified revision.
                        ((eq mode 'mixed) "--mixed")
                        ((eq mode 'hard) "--hard")
                        (t (error "Mode must be either 'soft, 'mixed, or 'hard")))))
-    (if without-config
-        (without-config-do
-          (git "reset" mode-string revision))
-        (git "reset" mode-string revision))))
+    (toggle-without-config without-config (git "reset" mode-string revision))))
 
 (defun-public mergetool ()
   "Executes the mergetool configured with git"