generated from threeal/project-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replace sample function to
git_clone
function
Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
- Loading branch information
Showing
4 changed files
with
35 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
function(mkdir_recursive DIR_PATH) | ||
file(MAKE_DIRECTORY "${DIR_PATH}") | ||
# Clone a Git repository to a specified directory. | ||
# | ||
# git_clone(<url> <dir>) | ||
# | ||
# This function clones a Git repository from the `<url>` and saves it to the | ||
# `<dir>` directory. It outputs a fatal error message if the operation fails. | ||
function(git_clone URL DIR) | ||
execute_process( | ||
COMMAND git clone "${URL}" "${DIR}" | ||
ERROR_VARIABLE ERR | ||
RESULT_VARIABLE RES) | ||
if(NOT RES EQUAL 0) | ||
message(FATAL_ERROR "Failed to clone '${URL}': ${ERR}") | ||
endif() | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
find_package(MyProject REQUIRED PATHS ${CMAKE_CURRENT_LIST_DIR}/../cmake) | ||
|
||
section("it should clone a Git repository") | ||
file(REMOVE_RECURSE repo) | ||
|
||
git_clone(https://github.com/threeal/cmake-starter repo) | ||
|
||
assert(EXISTS repo) | ||
assert_execute_process(git -C repo rev-parse --is-inside-work-tree) | ||
endsection() | ||
|
||
section("it should fail to clone an invalid Git repository") | ||
file(REMOVE_RECURSE repo) | ||
|
||
assert_fatal_error( | ||
CALL git_clone https://github.com repo | ||
MESSAGE "Failed to clone 'https://github.com'") | ||
|
||
assert(NOT EXISTS repo) | ||
endsection() |
This file was deleted.
Oops, something went wrong.