diff --git a/src/Git.cmake b/src/Git.cmake index a73e12ad..a51815af 100644 --- a/src/Git.cmake +++ b/src/Git.cmake @@ -319,13 +319,16 @@ function(git_add_remote) find_program(GIT_EXECUTABLE "git" REQUIRED) - # ensure that the given repository's remote is the current remote + # Get the list of the remotes execute_process( COMMAND "${GIT_EXECUTABLE}" "remote" "-v" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}" COMMAND_ERROR_IS_FATAL LAST OUTPUT_VARIABLE _remote_output ) - string(FIND "${_remote_output}" "${_fun_REMOTE_URL}" _find_index) + # Remove .git from the URL + string(REGEX REPLACE "^(.*)\.git$" "\\1" _fun_REMOTE_URL_no_git "${_fun_REMOTE_URL}") + # Check if the given remote already exists in the remote list + string(FIND "${_remote_output}" "${_fun_REMOTE_URL_no_git}" _find_index) # Add the given remote if it doesn't exist if(${_find_index} EQUAL -1)