Skip to content

A peer-to-peer stack for code collaboration

rad-project: Add other git remote

Thomas Scholtes96bc94821999
diff --git a/bin/rad-project b/bin/rad-project
index b231011..d831287 100755
--- a/bin/rad-project
+++ b/bin/rad-project
@@ -11,6 +11,7 @@
(import prelude/error-messages :as 'error)
(import prelude/validation :as 'validation)
(import prelude/cmd-parsing :unqualified)
+(import prelude/io :as 'io)
(import prelude/io-utils
'[set-git-config get-git-config process-git-with-exit!]
:unqualified)
@@ -123,7 +124,11 @@
["(see radicle.xyz/docs/storage for more info)\n"]])))
(match (prompt! question)
"1" (init-git-ipfs-repo cid-of-empty-repo)
- "2" (prompt! "Please input the remote git repo URL: ")
+ "2" (do
+ (def remote-url (prompt! "Please input the remote git repo URL: "))
+ (io/process-with-stdout-strict!
+ "git" ["remote" "add" "origin" remote-url] "")
+ remote-url)
"3" (if (eq? current-remote "")
(do (put-str! "No current remote origin set; please select 1 or 2.")
(exit! !))
diff --git a/docs/source/reference.rst b/docs/source/reference.rst
index d73b90a..e5acb4c 100644
--- a/docs/source/reference.rst
+++ b/docs/source/reference.rst
@@ -959,15 +959,28 @@ Like ``shell!``, but inherits stdin. WARNING: using ``shell!`` with
unsanitized user input is a security hazard! Example:
``(shell-no-stdin! "ls -Glah")``.
+``(write-file! filename contents)``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Write ``contents`` to file ``filename``.
+
``(process-with-stdout! command args to-write)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Like ``process!``, but captures stdout.
-``(write-file! filename contents)``
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+``(process-with-stdout-stderr-exitcode! command args to-write)``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Write ``contents`` to file ``filename``.
+Like ``process-with-stdout!``, but returns a vec
+``[stdout stderr exitcode]``. ``exitcode`` is either ``:ok`` or
+``[:error n]`` where ``n`` is a number.
+
+``(process-with-stdout-strict! command args to-write)``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Like ``process-with-stdout!``, but prints an error message and exits if
+the command fails.
``(init-file-dict! file)``
~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1008,13 +1021,6 @@ is used.
This requires the ``prelude/test/primitive-stub`` script to be loaded.
-``(process-with-stdout-stderr-exitcode! command args to-write)``
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Like ``process-with-stdout!``, but returns a vec
-``[stdout stderr exitcode]``. ``exitcode`` is either ``:ok`` or
-``[:error n]`` where ``n`` is a number.
-
``(prompt! prompt)``
~~~~~~~~~~~~~~~~~~~~
diff --git a/rad/prelude/io.rad b/rad/prelude/io.rad
index d5ece8b..df3a9aa 100644
--- a/rad/prelude/io.rad
+++ b/rad/prelude/io.rad
@@ -1,12 +1,15 @@
{:module 'prelude/io
:doc "Some basic I/O functions."
:exports '[print! shell! process! read-line! read-file-value! read-file-values!
- shell-with-stdout! shell-no-stdin! process-with-stdout! write-file!
+ shell-with-stdout! shell-no-stdin! write-file!
+ process-with-stdout! process-with-stdout-stderr-exitcode!
+ process-with-stdout-strict!
init-file-dict! read-file-key! write-file-key! ls! modify-file!
- install-fake-filesystem! process-with-stdout-stderr-exitcode! prompt!
+ install-fake-filesystem! prompt!
]}
(import prelude/patterns :unqualified)
+(import prelude/strings :as 'strings)
(import prelude/dict :unqualified)
(def read-line!
@@ -189,6 +192,23 @@ process exited normally and `[:error n]` otherwise. Example: `(process!
[ (process-with-stdout-stderr-exitcode! "false" [] "") ==> [[] [] [:error 1]] ]
)
+(def process-with-stdout-strict!
+ "Like `process-with-stdout!`, but prints an error message and exits if the command fails."
+ (fn [command args to-write]
+ (match (process-with-stdout-stderr-exitcode! command args to-write)
+ ['stdout _ :ok] stdout
+ ['stdout 'stderr [:error 'n]]
+ (do
+ (def command-line (strings/intercalate " " (cons command args)))
+ (put-str! (string-append "error: Command \"" command-line "\" exited with status code " (show n)))
+ (map (fn [l] (put-str! (string-append " stderr: " l))) stderr)
+ (exit! 1))
+ )))
+
+(:test "process-with-stdout-strict!"
+ [ (process-with-stdout-strict! "echo" ["hi"] "") ==> ["hi"] ]
+)
+
;; General utilities
(def ls!
"List the contents of the current working directory"
diff --git a/test/e2e/ProjectAppTest.hs b/test/e2e/ProjectAppTest.hs
index 370a51b..1449c99 100644
--- a/test/e2e/ProjectAppTest.hs
+++ b/test/e2e/ProjectAppTest.hs
@@ -1,6 +1,7 @@
module ProjectAppTest
( test_project_show_id
, test_project_checkout
+ , test_project_init_own_remote
) where
import Protolude
@@ -30,3 +31,17 @@ test_project_checkout = testCase "project checkout" $ do
withCurrentDirectory "project-name" $ do
showIdOut <- runTestCommand' "rad-project" ["show-id"] []
assertContains showIdOut projectId
+
+test_project_init_own_remote :: TestTree
+test_project_init_own_remote = testCase "project init own remote" $ do
+ prepareRadicle
+ _ <- runTestCommand' "rad-project" ["init"]
+ [ "project-name"
+ , "project desc"
+ , "2"
+ -- @.@ is a working remote URL that does not require an actual
+ -- remote. We need a working remote becuase @project init@ does
+ -- a @git fetch@.
+ , "."]
+ remoteUrl <- runTestCommand "git" ["remote", "get-url" ,"origin"]
+ assertEqual "Remote URL does not match" "." remoteUrl