]> gitweb.factorcode.org Git - factor.git/commitdiff
cli.git: Add more git commands.
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 5 Jul 2018 01:19:31 +0000 (20:19 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 5 Jul 2018 01:19:31 +0000 (20:19 -0500)
extra/cli/git/git.factor

index 1b589a008feefca86eb16782a5a38acb7b7dff34..2ea02a53cf678f5326d71fc7341168d04c94c02b 100644 (file)
@@ -9,6 +9,12 @@ IN: cli.git
 SYMBOL: cli-git-num-parallel
 cli-git-num-parallel [ cpus 2 * ] initialize
 
+: git-command>string ( quot -- string )
+    utf8 <process-reader> stream-contents [ blank? ] trim-tail ;
+
+: git-command>lines ( quot -- string )
+    utf8 <process-reader> stream-lines ;
+
 : git-clone-as ( uri path -- process ) [ { "git" "clone" } ] 2dip 2array append run-process ;
 : git-clone ( uri -- process ) [ { "git" "clone" } ] dip suffix run-process ;
 : git-pull* ( -- process ) { "git" "pull" } run-process ;
@@ -27,6 +33,12 @@ cli-git-num-parallel [ cpus 2 * ] initialize
 : git-remote-add ( path remote uri -- process ) '[ _ _ git-remote-add* ] with-directory ;
 : git-remote-get-url* ( remote -- process ) [ { "git" "remote" "get-url" } ] dip suffix run-process ;
 : git-remote-get-url ( path remote -- process ) '[ _ git-remote-get-url* ] with-directory ;
+: git-rev-parse* ( branch -- string ) [ { "git" "rev-parse" } ] dip suffix git-command>string ;
+: git-rev-parse ( path branch -- string ) '[ _ git-rev-parse* ] with-directory ;
+: git-diff-name-only* ( from to -- lines )
+    [ { "git" "diff" "--name-only" } ] 2dip 2array append git-command>lines ;
+: git-diff-name-only ( path from to -- lines )
+    [ git-diff-name-only* ] with-directory ;
 
 : git-repository? ( directory -- ? )
     ".git" append-path current-directory get prepend-path
@@ -34,9 +46,7 @@ cli-git-num-parallel [ cpus 2 * ] initialize
 
 : git-current-branch* ( -- name )
      ! { "git" "rev-parse" "--abbrev-ref" "HEAD" }
-     { "git" "name-rev" "--name-only" "HEAD" }
-     utf8 <process-reader> stream-contents
-     [ blank? ] trim-tail ;
+     { "git" "name-rev" "--name-only" "HEAD" } git-command>string ;
 
 : git-current-branch ( directory -- name )
     [ git-current-branch* ] with-directory ;