Skip to content

Instrument git_submodule_set_url. #1395

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
merged 1 commit into from
Aug 6, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions pygit2/decl/submodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ const char * git_submodule_branch(git_submodule *submodule);
const git_oid * git_submodule_head_id(git_submodule *submodule);

int git_submodule_status(unsigned int *status, git_repository *repo, const char *name, git_submodule_ignore_t ignore);

int git_submodule_set_url(git_repository *repo, const char *name, const char *url);
8 changes: 8 additions & 0 deletions pygit2/submodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ def url(self) -> Union[str, None]:
url = C.git_submodule_url(self._subm)
return maybe_string(url)

@url.setter
def url(self, url: str) -> None:
crepo = self._repo._repo
cname = ffi.new('char[]', to_bytes(self.name))
curl = ffi.new('char[]', to_bytes(url))
err = C.git_submodule_set_url(crepo, cname, curl)
check_error(err)

@property
def branch(self):
"""Branch that is to be tracked by the submodule."""
Expand Down
11 changes: 11 additions & 0 deletions test/test_submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ def test_url(repo: Repository) -> None:
assert SUBM_URL == s.url


def test_set_url(repo: Repository) -> None:
new_url = 'ssh://[email protected]:2222/my_repo'
s = repo.submodules[SUBM_PATH]
s.url = new_url
assert new_url == repo.submodules[SUBM_PATH].url
# Ensure .gitmodules has been correctly altered
with open(Path(repo.workdir, '.gitmodules'), 'r') as fd:
modules = fd.read()
assert new_url in modules


def test_missing_url(repo: Repository) -> None:
# Remove "url" from .gitmodules
with open(Path(repo.workdir, '.gitmodules'), 'wt') as f:
Expand Down
Loading