|
63 | 63 | (:method ((source git-at-commit-source)) |
64 | 64 | (format nil "~A" (commit source)))) |
65 | 65 |
|
| 66 | +(defstruct (submodule (:type vector)) |
| 67 | + name |
| 68 | + path |
| 69 | + sha1) |
| 70 | + |
| 71 | +(defun git-submodules (git-path) |
| 72 | + (loop for line in |
| 73 | + (run-output-lines "git" "-C" (truename git-path) "submodule" |
| 74 | + "--quiet" |
| 75 | + "foreach" |
| 76 | + "--recursive" |
| 77 | + "echo $name $sha1 $displaypath") |
| 78 | + for (name sha1 path) = (split-spaces line) |
| 79 | + collect (make-submodule :name name :path path :sha1 sha1))) |
| 80 | + |
| 81 | +(defun full-git-archive (git-path target-ref prefix output-file) |
| 82 | + "Create a tarball archive in OUTPUT-FILE of the full contents of the |
| 83 | +git checkout GIT-PATH, including submodules. The repo is archived at |
| 84 | +TARGET-REF, e.g. 'HEAD'. " |
| 85 | + (run "git" "-C" (truename git-path) |
| 86 | + "submodule" "update" "--init" "--recursive") |
| 87 | + (let ((submodules (git-submodules git-path))) |
| 88 | + (in-temporary-directory prefix |
| 89 | + (let* ((temp-base *default-pathname-defaults*)) |
| 90 | + (with-posix-cwd git-path |
| 91 | + (run "git" "archive" |
| 92 | + :format "tar" |
| 93 | + :prefix (format nil "~A/" prefix) |
| 94 | + "-o" (make-pathname :name (string-right-trim "/" prefix) |
| 95 | + :type "tar" |
| 96 | + :defaults temp-base) |
| 97 | + target-ref) |
| 98 | + (dolist (submodule submodules) |
| 99 | + (with-posix-cwd (submodule-path submodule) |
| 100 | + (let ((output (make-pathname :name (submodule-name submodule) |
| 101 | + :type "tar" |
| 102 | + :defaults temp-base))) |
| 103 | + (run "git" "archive" |
| 104 | + :format "tar" |
| 105 | + "-o" output |
| 106 | + :prefix (format nil "~A/~A/" |
| 107 | + prefix (submodule-path submodule)) |
| 108 | + (submodule-sha1 submodule)))))) |
| 109 | + ;; Back in the temp directory |
| 110 | + (dolist (tarball (directory "*.tar")) |
| 111 | + (run "tar" "xf" tarball)) |
| 112 | + (let ((combined "combined.tar") |
| 113 | + (combined-tgz "combined.tar.gz")) |
| 114 | + (run "tar" "cf" combined prefix) |
| 115 | + (run "gzip" "-vn9" "-S" ".gz" combined) |
| 116 | + (rename-file combined-tgz output-file)) |
| 117 | + output-file)))) |
| 118 | + |
66 | 119 | (defmethod make-release-tarball ((source git-source) output-file) |
67 | 120 | (let ((prefix (release-tarball-prefix source)) |
68 | 121 | (checkout (ensure-source-cache source))) |
69 | | - (in-temporary-directory prefix |
70 | | - (let ((temptar (merge-pathnames "package.tar")) |
71 | | - (tempgz (merge-pathnames "package.tar.gz"))) |
72 | | - (with-posix-cwd checkout |
73 | | - (with-binary-run-output temptar |
74 | | - (run "git" "archive" :format "tar" :prefix prefix |
75 | | - (target-ref source))) |
76 | | - (run "gzip" "-vn9" temptar) |
77 | | - (copy tempgz output-file)))))) |
| 122 | + (full-git-archive checkout (target-ref source) prefix output-file))) |
78 | 123 |
|
0 commit comments