Skip to content

git: reject remote names that are empty or contain whitespace#9155

Open
eyupcanakman wants to merge 1 commit into
jj-vcs:mainfrom
eyupcanakman:fix/remote-name-whitespace-9099
Open

git: reject remote names that are empty or contain whitespace#9155
eyupcanakman wants to merge 1 commit into
jj-vcs:mainfrom
eyupcanakman:fix/remote-name-whitespace-9099

Conversation

@eyupcanakman
Copy link
Copy Markdown

Passing a remote name with spaces (e.g. jj git remote add "my remote" url) causes a panic in libgit2. Empty names also panic.

Added Empty and WithWhitespace variants to GitRemoteNameError so validate_remote_name rejects these with a clear message before they reach libgit2.

Fixes #9099

@eyupcanakman eyupcanakman requested a review from a team as a code owner March 21, 2026 05:51
@eyupcanakman eyupcanakman force-pushed the fix/remote-name-whitespace-9099 branch from f98ed63 to 597f07a Compare March 21, 2026 06:46
Comment thread lib/src/git.rs Outdated

fn validate_remote_name(name: &RemoteName) -> Result<(), GitRemoteNameError> {
if name == REMOTE_NAME_FOR_LOCAL_GIT_REPO {
if name.as_str().is_empty() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, using gix::remote::name::validated() now.

Comment thread cli/tests/test_git_remotes.rs Outdated
}

#[test]
fn test_git_remote_name_with_whitespace() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CLI tests are slow. If we need to test various error conditions, it's better to add jj-lib tests.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Moved the detailed error condition tests to lib/tests/test_git.rs. The CLI test now has a single case with a comment pointing to the lib tests.

@martinvonz
Copy link
Copy Markdown
Member

nit: Please squash the two commits (see https://docs.jj-vcs.dev/latest/contributing/#commit-guidelines)

@josephlou5
Copy link
Copy Markdown
Contributor

Thanks for doing this! I know I self-assigned the issue but haven't had the time to get around to it...

@eyupcanakman eyupcanakman force-pushed the fix/remote-name-whitespace-9099 branch from 62a9a7c to 1f335dd Compare March 22, 2026 09:55
@eyupcanakman
Copy link
Copy Markdown
Author

Squashed.

Copy link
Copy Markdown
Contributor

@yuja yuja left a comment

Choose a reason for hiding this comment

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

Thanks.

Comment thread lib/src/git.rs Outdated
Comment on lines +151 to +152
#[error("Invalid Git remote name: {0}")]
InvalidName(#[from] gix::remote::name::Error),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: remove : {0} which should be printed as a source error.

@josephlou5
Copy link
Copy Markdown
Contributor

Hey @eyupcanakman, any updates on this?

Use `gix::remote::name::validated()` to reject invalid git remote names
(empty strings, whitespace, and other names that git itself would reject)
at the jj-lib level before they propagate to git operations.

Fixes jj-vcs#9099
@eyupcanakman eyupcanakman force-pushed the fix/remote-name-whitespace-9099 branch from 1f335dd to 265b27a Compare June 1, 2026 04:19
@eyupcanakman
Copy link
Copy Markdown
Author

Sorry for the lag on this. Pushed yuja's last nit just now, dropping the : {0} so the gix error only shows up in the Caused by chain instead of twice.

Copy link
Copy Markdown
Contributor

@yuja yuja left a comment

Choose a reason for hiding this comment

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

Thanks.

Comment thread lib/tests/test_git.rs
"https://example.com/",
None,
gix::remote::fetch::Tags::default(),
&StringExpression::all(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you rebase this PR and update the tests accordingly?

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.

Bug: Remote name with whitespace causes a panic

4 participants