diff --git a/packages/bash/src/main/sh/buildstamp.sh b/packages/bash/src/main/sh/buildstamp.sh index cb39509..ed20c26 100644 --- a/packages/bash/src/main/sh/buildstamp.sh +++ b/packages/bash/src/main/sh/buildstamp.sh @@ -44,7 +44,8 @@ if [[ $opt_git == "true" ]]; then git_commit_branch = $(git rev-parse --abbrev-ref HEAD) fi git_commit_id=$(git rev-parse HEAD) - git_repo_url=$(git config --get remote.origin.url) + git_remote=$(git remote show) + git_repo_url=$(git config --get remote.${git_remote}.url) re="([^./:]+\/[^./]+)(\.git)?$" if [[ $git_repo_url =~ $re ]]; then git_repo_name=${BASH_REMATCH[1]} diff --git a/packages/bin/src/main/go/buildstamp/buildstamp.go b/packages/bin/src/main/go/buildstamp/buildstamp.go index 9933a05..e6edf50 100644 --- a/packages/bin/src/main/go/buildstamp/buildstamp.go +++ b/packages/bin/src/main/go/buildstamp/buildstamp.go @@ -74,7 +74,7 @@ func GetPkgInfo(cwd string) PackageJson { func GetGitInfo(cwd string) GitInfo { var _, commitId, _ = invoke("git", []string{"rev-parse", "HEAD"}, cwd) - var _, repoUrl, _ = invoke("git", []string{"config", "--get", "remote.origin.url"}, cwd) + var repoUrl = getGitRepoUrl(cwd) var repoName = string(repoUrl[strings.LastIndex(repoUrl, ":")+1 : strings.LastIndex(repoUrl, ".")]) var commitBranch = getCommitBranch(cwd) @@ -86,6 +86,13 @@ func GetGitInfo(cwd string) GitInfo { } } +func getGitRepoUrl(cwd string) string { + var _, remote, _ = invoke("git", []string{"remote", "show"}, cwd) + var _, repoUrl, _ = invoke("git", []string{"config", "--get", "remote." + remote + ".url"}, cwd) + + return repoUrl +} + func getCommitBranch(cwd string) string { var commitBranch = getFirstNonEmpty(os.Getenv("CI_COMMIT_BRANCH"), os.Getenv("GITHUB_REF_NAME")) if commitBranch == "" { diff --git a/packages/core/src/main/ts/buildstamp.ts b/packages/core/src/main/ts/buildstamp.ts index c20c1a2..edb3fc7 100644 --- a/packages/core/src/main/ts/buildstamp.ts +++ b/packages/core/src/main/ts/buildstamp.ts @@ -53,7 +53,7 @@ export const getCommitBranch = async (cwd: string, env: Record): Promise => { const { stdout: git_commit_id } = await spawn('git', ['rev-parse', 'HEAD'], cwd) - const { stdout: git_repo_url } = await spawn('git', ['config', '--get', 'remote.origin.url'], cwd) + const git_repo_url = await getGitRepoUrl(cwd) const git_commit_branch = await getCommitBranch(cwd, env) const git_repo_name = (git_repo_url.match(/([^./:]+\/[^./]+)(\.git)?$/) || [])[1] @@ -65,6 +65,12 @@ export const getGitInfo = async (cwd: string, env: Record => { + const { stdout: git_remote } = await spawn('git', ['remote', 'show'], cwd) + const { stdout: git_repo_url } = await spawn('git', ['config', '--get', `remote.${git_remote}.url`], cwd) + return git_repo_url +} + // https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables // https://docs.gitlab.com/ee/ci/variables/predefined_variables.html // https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html#Predefined+Server+Build+Parameters