]> gitweb.factorcode.org Git - factor.git/commitdiff
cli.git: add `git checkout` and cloning bare repos
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 17 Aug 2023 23:35:45 +0000 (18:35 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 18 Aug 2023 00:55:46 +0000 (19:55 -0500)
extra/cli/git/git.factor

index 1c1549f1b37d42381f9fbe12db29f81516007366..3fc8229c11e95faae0005ff1c9c41137a7794d58 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2017 Doug Coleman.
 ! See https://factorcode.org/license.txt for BSD license.
-USING: accessors arrays concurrency.combinators
-concurrency.semaphores io io.directories io.encodings.utf8
-io.files.info io.launcher io.pathnames kernel math namespaces
-sequences splitting system-info unicode ;
+USING: accessors arrays combinators.short-circuit
+concurrency.combinators concurrency.semaphores io io.directories
+io.encodings.utf8 io.files.info io.launcher io.pathnames kernel
+math namespaces sequences splitting system-info unicode ;
 IN: cli.git
 
 SYMBOL: cli-git-num-parallel
@@ -12,8 +12,12 @@ cli-git-num-parallel [ cpus 2 * ] initialize
 : git-command>string ( desc -- string )
     utf8 <process-reader> stream-contents [ blank? ] trim-tail ;
 
+: git-clone-bare-as ( uri path -- process ) [ { "git" "clone" "--bare" } ] 2dip 2array append run-process ;
+: git-clone-bare ( uri -- process ) [ { "git" "clone" "--bare" } ] dip suffix run-process ;
 : git-clone-as ( uri path -- process ) [ { "git" "clone" } ] 2dip 2array append run-process ;
 : git-clone ( uri -- process ) [ { "git" "clone" } ] dip suffix run-process ;
+: git-worktree-add ( path branch -- process ) '{ "git" "worktree" "add" _ _ } run-process ;
+: git-worktree-force-add ( path branch -- process ) '{ "git" "worktree" "add" "-f" _ _ } run-process ;
 : git-pull* ( -- process ) { "git" "pull" } run-process ;
 : git-pull ( path -- process ) [ git-pull* ] with-directory ;
 : git-fetch-all-desc ( -- process ) { "git" "fetch" "--all" } ;
@@ -58,6 +62,26 @@ cli-git-num-parallel [ cpus 2 * ] initialize
 : git-directory-name ( string -- string' )
     file-name ".git" ?tail drop ;
 
+: git-is-bare-repository* ( -- ? )
+    { "git" "rev-parse" "--is-bare-repository" } git-command>string "true" = ;
+
+: git-is-bare-repository ( path -- ? )
+    '[ git-is-bare-repository* ] with-directory ;
+
+: git-bare-directory? ( directory -- ? )
+    {
+        [ ?file-info [ directory? ] [ f ] if* ]
+        [ git-is-bare-repository ]
+    } 1&& ;
+
+: sync-bare-repository ( url -- process )
+    dup git-directory-name git-bare-directory?
+    [ git-directory-name git-fetch-all ] [ git-clone-bare ] if ;
+
+: sync-bare-repository-as ( url path -- processes )
+    dup git-bare-directory?
+    [ nip git-fetch-all ] [ git-clone-bare-as ] if ;
+
 : sync-repository ( url -- process )
     dup git-directory-name git-directory?
     [ git-directory-name git-pull ] [ git-clone ] if ;