diff options
author | Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> | 2021-07-28 15:16:30 +0100 |
---|---|---|
committer | Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> | 2021-09-27 15:41:24 +0100 |
commit | 1dad57d47614546240061fd942d1ff8e6e54eb64 (patch) | |
tree | 8d6cd6d8761817187ad6aa6190e606f84fd75d5a | |
parent | 3df459ce8233f755c7eebc2b67f0ca6465ebd927 (diff) | |
download | extra-cmake-modules-1dad57d47614546240061fd942d1ff8e6e54eb64.tar.gz extra-cmake-modules-1dad57d47614546240061fd942d1ff8e6e54eb64.tar.bz2 |
Handle git remotes that aren't called origin in _repository_name()
I was seeing `error: No such remote 'origin'` in the cmake output.
This commit avoids hardcoding `origin` as the upstream URL and instead
uses the `git rev-parse @{u}` to get the configured upstream.
As a follow-up we may want to check if this should be executed by default,
but for now this fixes a warning that I'm seeing with various projects.
-rw-r--r-- | kde-modules/KDECMakeSettings.cmake | 14 | ||||
-rwxr-xr-x | toolchain/generate-fastlane-metadata.py | 4 |
2 files changed, 15 insertions, 3 deletions
diff --git a/kde-modules/KDECMakeSettings.cmake b/kde-modules/KDECMakeSettings.cmake index 251f7cff..319a8932 100644 --- a/kde-modules/KDECMakeSettings.cmake +++ b/kde-modules/KDECMakeSettings.cmake @@ -297,14 +297,24 @@ endif() # Download translations function(_repository_name reponame dir) - execute_process(COMMAND git remote get-url --all origin - OUTPUT_VARIABLE giturl + execute_process(COMMAND git rev-parse --symbolic-full-name @{u} + OUTPUT_VARIABLE upstream_ref RESULT_VARIABLE exitCode WORKING_DIRECTORY "${dir}") + string(REGEX REPLACE "refs/remotes/([^/]+)/.*" "\\1" gitorigin "${upstream_ref}") + if(exitCode EQUAL 0) + message(DEBUG "Git upstream inferred as ${gitorigin}, upstream ref was ${upstream_ref}") + execute_process(COMMAND git remote get-url --all "${gitorigin}" + OUTPUT_VARIABLE giturl + RESULT_VARIABLE exitCode + WORKING_DIRECTORY "${dir}") + endif() if(exitCode EQUAL 0) + message(DEBUG "Git URL inferred as ${giturl}") string(REGEX MATCHALL ".+kde\\.org[:\\/]([-A-Za-z0-9\\/]+)(.git)?\\s*" "" ${giturl}) set(${reponame} ${CMAKE_MATCH_1}) + message(DEBUG "Repository inferred as ${${reponame}}") endif() if(NOT ${reponame}) diff --git a/toolchain/generate-fastlane-metadata.py b/toolchain/generate-fastlane-metadata.py index f39acc3a..642a76d3 100755 --- a/toolchain/generate-fastlane-metadata.py +++ b/toolchain/generate-fastlane-metadata.py @@ -339,7 +339,9 @@ def processAppstreamFile(appstreamFileName, desktopFileName, iconBaseName): # Try to figure out the source repository if arguments.source and os.path.exists(os.path.join(arguments.source, '.git')): - output = subprocess.check_output('git remote show -n origin', shell=True, cwd = arguments.source).decode('utf-8') + upstream_ref = subprocess.check_output(['git', 'rev-parse', '--symbolic-full-name', '@{u}'], cwd=arguments.source).decode('utf-8') + remote = upstream_ref.split('/')[2] + output = subprocess.check_output(['git', 'remote', 'show', '-n', remote], cwd=arguments.source).decode('utf-8') result = re.search(' Fetch URL: (.*)\n', output) data['source-repo'] = result.group(1) |