mor

Cross platform dependency manager

commit 25f9c9c847fbbb67dca6be8a3f86e5bd75c03ea6
parent edfb6a18162e0dedff883987a6cf6eb74a84448d
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Thu, 24 Oct 2024 02:00:44 +0530

Add git clone feature

Update README with proper examples

Update README FAQ about the omission of 'clean' command

Update requirements.ini with git example

Bump version to 0.8
3 files changed, 53 insertions(+), 14 deletions(-)
M
README
|
6
+++++-
M
mor.cmd
|
48
++++++++++++++++++++++++++++++++++++++----------
M
requirements.ini
|
13
++++++++++---
diff --git a/README b/README
@@ -135,7 +135,7 @@ Example
 
 	[folder/]
 	libfoo-2.7=$git/releases/libfoo/releases/v26.1/foo-26.1-osx-universal.zip
-	libfoo-git-2.7=$github/foo/libfoo.git
+	libfoo-git-2.7=$github/foo/libfoo.git@master
 
 Windows
 -------

@@ -172,6 +172,10 @@ I wanted mor to be as language agnostic as possible and I wanted the core
 variables to be ASCII clean. This is also the reason why the status messages
 are mostly made up of symbols.
 
+> Why no 'clean' command?
+To keep things simple.
+Just do `rm -rf 'directory` or `rmdir /s/q directory` if using cmd
+
 > Where are the damn CHANGELOGs?
 For the complete changelog,
         git notes show v0.2~1..
diff --git a/mor.cmd b/mor.cmd
@@ -1,7 +1,7 @@
 @echo off
 setlocal
-set mor_version=0.7
-set root_dir=%cd%\out
+set mor_version=0.8
+set root_dir=%cd%
 for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
 
 rem default values

@@ -45,7 +45,7 @@ setlocal EnableDelayedExpansion
 					call set val=%%val:$!varname!=%%t%%
 				)
 			)
-			if "!current_section:~1,1!" == "$" (
+			if "!current_section:~1!" == "$" (
 				if "!tok!"=="/" (
 					set root_dir=!val!
 				) else (

@@ -130,15 +130,30 @@ setlocal EnableDelayedExpansion
 	if not exist "!current_target_dir!" mkdir "!current_target_dir!"
 	:MOR_KEY_VAULE
 	if "%~1" == "" goto :eof
-	rem TODO Check if this for loop is really necessary
+	rem %ext% will have the last '.' splitted word
 	for %%i in (%2) do set ext=%%~xi
-	where /q curl
-	if ERRORLEVEL 1 (
-		call :download_archive !current_target_dir! %1 %2 !ext!
-		if ERRORLEVEL 1 exit /b !ERRORLEVEL!
+
+	set repo_url=%~2
+	rem the 'y' is there to prevent %ext% from taking over the script
+	if not y%ext:git@=%==y%ext% (
+		rem Splitting a string using string
+		set i=1
+		set "fn!i!=%repo_url:.git@=" & set /A i+=1 & set "fn!i!=%"
+		set repo_url=!fn1!
+		set repo_branch=!fn2!
+	)
+
+	if not "!repo_branch!"=="" (
+		call :clone_git "!current_target_dir!" %1 "!repo_url!" "!repo_branch!"
 	) else (
-		call :download_archive_curl !current_target_dir! %1 %2 !ext!
-		if ERRORLEVEL 1 exit /b !ERRORLEVEL!
+		where /q curl
+		if ERRORLEVEL 1 (
+			call :download_archive !current_target_dir! %1 %2 !ext!
+			if ERRORLEVEL 1 exit /b !ERRORLEVEL!
+		) else (
+			call :download_archive_curl !current_target_dir! %1 %2 !ext!
+			if ERRORLEVEL 1 exit /b !ERRORLEVEL!
+		)
 	)
 
 

@@ -224,6 +239,19 @@ setlocal
 endlocal
 goto :eof
 
+:clone_git <directory> <name> <repo> <branch>
+setlocal EnableDelayedExpansion
+	echo G %~3 (%~4)
+	set dest_dir="%~1\%~2"
+	if exist !dest_dir! (
+		call :logi "!dest_dir! Alreay exists"
+	) else (
+		git clone "%~3" -b "%~4" !dest_dir! 2>>mor.log
+	)
+	exit /b %ERRORLEVEL%
+endlocal DisableDelayedExpansion
+goto :eof
+
 :main
 setlocal EnableDelayedExpansion
 :parse
diff --git a/requirements.ini b/requirements.ini
@@ -1,6 +1,7 @@
 ; 1st comment
 [$]
-a=https://geths.org
+a=https://getsh.org
+github=https://github.com
 mor=$a
 /=build
 

@@ -14,7 +15,7 @@ mor=$a
 /=precompiled testing
 
 [#baddynamic]
-/=dynamic
+/=badlink
 
 [@lib]
 test1=0.1

@@ -32,6 +33,7 @@ test1=0.9
 
 [badlink]
 something-3.3=https://getsh.org/wrong
+test1-0.9=$nothing/index.html
 
 [testing]
 ;libfoo-2.7=https://github.com/protocolbuffers/protobuf/releases/download/v26.1/protoc-26.1-osx-aarch_64.zip

@@ -39,7 +41,6 @@ test1-0.1=https://getsh.org/index.html
 test2-0.3=https://getsh.org/bharatvaj/pubkey.asc
 
 [dynamic]
-test1-0.9=$nothing/index.html
 test4-0.1=$mor/index.html
 
 [secondtest]

@@ -48,3 +49,9 @@ test1-45=https://google.com/
 
 [curlfail]
 test3-0.1=https://getsh.org/something 32239423
+
+[git]
+libhttp=https://github.com/bharatvaj/libclog.git@master
+
+[gitdynamic]
+libhttp=$github/markusfisch/libhttp.git@master