Skip to content

Commit

Permalink
refactor(core): minor changes in minemacs-update-restore-locked
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Oct 9, 2023
1 parent de76af5 commit 7ac449f
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions elisp/+minemacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -490,22 +490,23 @@ When called with C-u or with RESTORE-FROM-BACKUP, it will restore the lockfile
from backups, not Git."
(interactive "P")
(let* ((lockfile (concat straight-base-dir "straight/versions/default.el"))
(default-directory (vc-git-root lockfile)))
(if restore-from-backup
(let ((backup-dir (concat minemacs-local-dir "minemacs/versions/")))
(message "[MinEmacs] Trying to restore the lockfile from backups.")
(if-let* ((_ (file-exists-p backup-dir))
(backups (directory-files backup-dir nil "[^.][^.]?$"))
(restore-backup-file (completing-read "Select which backup file to restore: " backups))
(last-backup (expand-file-name restore-backup-file backup-dir)))
(if (not (file-exists-p last-backup))
(user-error "[MinEmacs] No backup file")
(copy-file last-backup lockfile 'overwrite-existing)
(message "[MinEmacs] Restored the last backup from \"%s\"" restore-backup-file))))
(message "[MinEmacs] Reverting file \"%s\" to the original" lockfile)
(unless (zerop (vc-git-revert lockfile))
;; Signal an error when the `vc-git-revert' returns non-zero
(user-error "[MinEmacs] An error occured when trying to revert \"%s\"" lockfile)))
(default-directory (vc-git-root lockfile))
(backup-dir (concat minemacs-local-dir "minemacs/versions/")))
(if (not restore-from-backup)
(progn
(message "[MinEmacs] Reverting file \"%s\" to the original" lockfile)
(unless (zerop (vc-git-revert lockfile))
;; Signal an error when the `vc-git-revert' returns non-zero
(user-error "[MinEmacs] An error occured when trying to revert \"%s\"" lockfile)))
(message "[MinEmacs] Trying to restore the lockfile from backups.")
(if-let* ((_ (file-exists-p backup-dir))
(backups (directory-files backup-dir nil "[^.][^.]?$"))
(restore-backup-file (completing-read "Select which backup to restore: " backups))
(last-backup (expand-file-name restore-backup-file backup-dir)))
(if (not (file-exists-p last-backup))
(user-error "[MinEmacs] No backup file")
(copy-file last-backup lockfile 'overwrite-existing)
(message "[MinEmacs] Restored the last backup from \"%s\"" restore-backup-file))))
;; Restore packages to the versions pinned in lockfile
(message "[MinEmacs] Restoring packages to the reverted lockfile versions")
(straight-x-thaw-pinned-versions)
Expand Down

0 comments on commit 7ac449f

Please sign in to comment.