Implement h--cal-git-clone-in-dir

This function is in charge of using a underlying git subprocess to
clone a remote repository locally.
This commit is contained in:
Félix Baylac-Jacqué 2022-05-05 11:53:43 +02:00
parent 08b1a44d8b
commit bc5e1b31ae
2 changed files with 20 additions and 3 deletions

View file

@ -49,7 +49,7 @@ If DIR doesn't exists, we create it first."
(let ((d (file-name-as-directory dir)))
(progn
(unless (file-directory-p d) (make-directory d t))
(h--call-git-in-dir d "init" ))))
(h--call-git-in-dir d "init"))))
;; Test Dirs Setup
;;;;;;;;;;;;;;;;;
@ -239,5 +239,18 @@ For reference: a empty test root looks like this:
(should (equal (h--filepath-from-clone-url "git@github.com:NinjaTrappeur/h.el.git") "github.com/NinjaTrappeur/h.el"))
(should (equal (h--filepath-from-clone-url "git@github.com:NinjaTrappeur/h.el") "github.com/NinjaTrappeur/h.el")))
(ert-deftest h--test-git-clone-in-dir ()
"Test the h--git-clone-in-dir function"
(h--tests-run-on-testroot-1
(lambda (dir)
(let
((tmpdir (make-temp-file "h-test-" t)))
(progn
(h--git-clone-in-dir
(format "file://%s" (concat dir "example1.tld/user1/proj1/"))
tmpdir)
(should (file-exists-p (format "%s/.git" tmpdir)))
(delete-directory tmpdir t))))))
(provide 'h-tests)
;;; h-tests.el ends here

8
h.el
View file

@ -59,10 +59,14 @@ Errors out if we can't find it."
git-from-bin-path
(error "Can't find git. Is h-git-bin correctly set?")))))
(defun h--call-git-in-dir (dir args)
(defun h--call-git-in-dir (dir &rest args)
"Call the git binary as pointed by h-git-bin in DIR with ARGS."
(let ((default-directory dir))
(process-file (h--git-path) nil nil nil args)))
(apply 'process-file (seq-concatenate 'list `(,(h--git-path) nil "*h git log*" nil) args))))
(defun h--git-clone-in-dir (clone-url checkout-filepath)
"Clone the CLONE-URL repo at CHECKOUT-FILEPATH."
(h--call-git-in-dir "~/" "clone" clone-url checkout-filepath))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Internal: builtin fetchers