Skip to content

fix: Deal with remote urls aliased using insteadOf directives #1151

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

Merged

Conversation

larsks
Copy link
Contributor

@larsks larsks commented Jan 22, 2025

Purpose

Rationale

Previously, python-semantic-release would attempt to use the raw url from
the repository configuration (me:myproject in the above example), and
would fail to parse it because it's not actually a url. With this change,
psr instead calls out to git remote get-url, which fully expands any aliases via git.

How I tested

Created a unit test that will modify a git configuration with a remote origin defined with an alias and the associated alias defined separately. The runtime context is loaded and then validated through the GitHub VCS client.

How to Verify

git fetch pull/1151/head pr-1151
git checkout pr-1151~1 --detach

# validate the added test will replicate the failure on the original code
pytest -vv -k test_git_remote_url_w_insteadof_alias

# Checkout the latest
git checkout pr-1151

# Run the tests again and see the failure is resolved
pytest -vv -k test_git_remote_url_w_insteadof_alias

@codejedi365
Copy link
Contributor

@larsks, thanks for the PR resolution, I'll try to have it into this weeks release. If there is a unit test we can add maybe to test_config that would be great. I'm thinking we probably don't need the or statement and should just default to the get url?

@larsks
Copy link
Contributor Author

larsks commented Jan 23, 2025

If there is a unit test we can add maybe to test_config that would be great.

Sure, I'll try to take a look at that this evening.

I'm thinking we probably don't need the or statement and should just default to the get url?

You mean here?

remote_url = raw.remote.url or git_repo.remote(raw.remote.name).url

I suspect you're correct; I wasn't sure where/how raw.remote.url was set. I'll make this change as well.

@codejedi365
Copy link
Contributor

I suspect you're correct; I wasn't sure where/how raw.remote.url was set. I'll make this change as well.

Oh wait, disregard. The or is correct. As the raw is the actual configuration from the user. They can pass the URL in the configuration.

Let me know if you need me to build the test. You are going to want to use on of our default repo fixtures. The easiest and fastest is repo_initial_commit.

@larsks larsks force-pushed the fix/handle-insteadof branch 3 times, most recently from cb1d587 to f872aff Compare January 23, 2025 23:34
@larsks
Copy link
Contributor Author

larsks commented Jan 23, 2025

I've put together a test, but it's the first test that manipulates the git configuration so there wasn't a model to follow. Let me know what you think.

@larsks larsks force-pushed the fix/handle-insteadof branch 2 times, most recently from 814afd3 to 174e4e3 Compare January 23, 2025 23:39
@codejedi365 codejedi365 force-pushed the fix/handle-insteadof branch 2 times, most recently from c5b1af5 to 32cf1d8 Compare January 25, 2025 20:28
codejedi365 and others added 3 commits January 25, 2025 16:22
…dOf` configurations

Git permits creating URL aliases through the use of the insteadOf directive
[1]. For example, given a configuration like this:

    [url "ssh://git@github.com/larsks/"]
    insteadOf = me:

We can reference a remote project like this:

    git clone me:myproject

Which will act as if we had actually typed:

    git clone ssh://git@github.com/larsks/myproject

Previously, python-semantic-release would attempt to use the raw url from
the repository configuration (`me:myproject` in the above example), and
would fail to parse it because it's not actually a url. With this change,
psr instead calls out to `git remote get-url`, which fully expands the url
for us.

[1]: https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf

Closes: python-semantic-release#1150
@codejedi365
Copy link
Contributor

I've put together a test, but it's the first test that manipulates the git configuration so there wasn't a model to follow. Let me know what you think.

It was a good skeleton, Thanks! Made some adjustments and expanded the tests to run across all the VCS types as they all implement remote_url().

@codejedi365 codejedi365 merged commit 4045037 into python-semantic-release:master Jan 25, 2025
12 checks passed
@codejedi365
Copy link
Contributor

🎉 This PR has been published as part of Version 9.17.0 🎉

You can find more information about this release on the GitHub Releases page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request support git "insteadOf" url aliases
2 participants