Skip to content

Commit

Permalink
package-build--cleanup: Work around mercurial's broken purge command
Browse files Browse the repository at this point in the history
I tried using these arguments:

  --all                  purge ignored files too
  -y --noninteractive    do not prompt, automatically pick the
                         first choice for all prompts

But sadly that does not work as advertised:

  $ hg purge --all -y
  permanently delete 1 ignored files? (yN) n
  abort: removal cancelled

  $ hg -y purge --all
  permanently delete 1 ignored files? (yN) n
  abort: removal cancelled

  $ hg purge --all --noninteractive
  permanently delete 1 ignored files? (yN) n
  abort: removal cancelled

Additionally there is no argument to include "unknown" files, i.e.,
files that are neither tracked nor ignored.  No such files should
exist in our case, because no human touches these repositories, but
they do.  So it appears that when one checks out a new revision that
lacks some files that the previously checked out revision had, these
files are left in the worktree.

So we have no choice but to manually clean out the ignored and unknown
files, and then run the purge command anyway, in case there happen to
be other files that have to be purged; and hope that it will comply
and remove those.
  • Loading branch information
tarsius committed Aug 20, 2023
1 parent 0081876 commit c399e2c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions package-build.el
Original file line number Diff line number Diff line change
Expand Up @@ -1461,11 +1461,17 @@ in `package-build-archive-dir'."
(delete-directory tmp-dir t nil))))

(defun package-build--cleanup (rcp)
(cond
((cl-typep rcp 'package-git-recipe)
(package-build--call-process rcp "git" "clean" "-f" "-d" "-x"))
((cl-typep rcp 'package-hg-recipe)
(package-build--call-process rcp "hg" "purge" "--all" "--noninteractive"))))
(cond ((cl-typep rcp 'package-git-recipe)
(package-build--call-process rcp "git" "clean" "-f" "-d" "-x"))
((cl-typep rcp 'package-hg-recipe)
;; Mercurial's interface is so much better than Git's, they said.
(with-temp-buffer
(process-file "hg" nil t nil "status" "--no-status" "--unknown" "-0")
(mapc #'delete-file (split-string (buffer-string) "\0" t)))
(with-temp-buffer
(process-file "hg" nil t nil "status" "--no-status" "--ignored" "-0")
(mapc #'delete-file (split-string (buffer-string) "\0" t)))
(package-build--call-process rcp "hg" "purge"))))

;;;###autoload
(defun package-build-all ()
Expand Down

0 comments on commit c399e2c

Please sign in to comment.