Skip to content

Use a more generic way to pull repo name #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ export default class ServerlessGitVariables {
break
}
case 'repository': {
const pathName = await _exec('git rev-parse --show-toplevel')
value = path.basename(pathName)
const firstRemoteName = await _exec('git remote | head -1')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the better option here would be to default to origin and allow a config escape hatch instead of assuming the first remote is the right one (I also think this isn't guaranteed to work on all systems, since not all systems have access to head)

Copy link
Author

@efimk-lu efimk-lu Oct 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jacob-meacham thinking out loud, no need to change the default behavior, so we won't break any legacy system using this plugin, and use a config escape to override the behavior and use git config --get remote.origin.url . WDYT?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm compelled by your case - I think that this is strictly more correct (though I'd release it as a breaking change), so I think we should just go for it and either add configuration to set the remote you want to pull or just use origin which I expect is right the vast majority of cases

const remoteUrl = await _exec(
`git config --get remote.${firstRemoteName}.url`,
)
value = path.basename(remoteUrl, '.git')
break
}
case 'tags':
Expand Down