From: Matthias Kruk Date: Fri, 7 Jan 2022 13:37:00 +0000 (+0900) Subject: include/git: Add git_remote_get() function X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=2c00c71989b10b0e65e946804ea6bdedf8545048;p=toolbox include/git: Add git_remote_get() function This commit adds the git_remote_get() function, which can be used to determine the URLs of a repository's remotes. --- diff --git a/include/git.sh b/include/git.sh index 7e4c0c1..a458ccf 100644 --- a/include/git.sh +++ b/include/git.sh @@ -165,3 +165,18 @@ git_commit() { return 0 } + +git_remote_get() { + local repository="$1" + local remote="$2" + + local url + + if ! url=$(cd "$repository" && git remote get-url "$remote"); then + log_error "Could not get URL of remote $remote in $repository" + return 1 + fi + + echo "$url" + return 0 +}