Skip to content
Open
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: 1 addition & 1 deletion builtin/credential-store.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static int parse_credential_file(const char *fn,
return found_credential;
}

while (strbuf_getline_lf(&line, fh) != EOF) {
while (strbuf_getline(&line, fh) != EOF) {
if (!credential_from_url_gently(&entry, line.buf, 1) &&
entry.username && entry.password &&
credential_match(c, &entry, match_password)) {
Expand Down
18 changes: 6 additions & 12 deletions t/t0302-credential-store.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,16 @@ invalid_credential_test "scheme" ://user:pass@example.com
invalid_credential_test "valid host/path" https://user:pass@
invalid_credential_test "username/password" https://pass@example.com

test_expect_success 'get: credentials with DOS line endings are invalid' '
test_expect_success 'get: credentials with DOS line endings are valid' '

@dscho dscho Oct 7, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm. This reverts c03859a, and I wonder whether we're not actually making things worse that way: We're essentially walking back a promise that we've upheld for 6 years...

@i80487 i80487 Oct 20, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

From my perspective as a user, it seems both normal and reasonable for "Git for Windows" to support a credentials file with CRLF line endings, since the program is natively intended for Windows.

Also, CRLF handling seems currently to be inconsistent: CRLF credentials are considered invalid at line 146 (test_expect_success 'get: credentials with DOS line endings are invalid'), but valid at line 163 (test_expect_success 'get: credentials with path and DOS line endings are valid') ?!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@i80487 what you missed, though, is that we're not even talking about user-facing files, but about files that are written by Git. Some users may feel free to muck with those, and change the line endings. That's what this PR tries to accommodate. I don't think it would set a good precedent, though. Soon we'd have to add patches left and right to accommodate for all sorts of subtle inconsistencies users would introduce into Git's internal files, when it would be better to draw a hard line: Iff you want to mess with those files, you're completely on your own, we won't cover up your mistakes.

@i80487 i80487 Nov 13, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@dscho: As a software engineer, I fully understand that you may not want to support every possible case that users might introduce.

As an end user of "git-for-windows", please note that .gitconfig and .git-credentials are text files stored in the home directory. They’re not internal Git files stored in a .git folder, but configuration and credential files. As with many other applications, it seems to me both legitimate and reasonable to be able to edit them (while following the syntax) with a text editor rather than having to use Git commands.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@i80487 I understand your desire, but you're mixing two concepts here. .gitconfig is supposed to be edited by the user, typically using the git config command. The .git-credentials file is in a very different category, it is the backing file of git-credential--store, and as such it totally is not meant to be edited by users, certainly not directly via a text editor. Just because you can does not mean that it is a good idea.

Take for example packfiles. You can edit .pack files with a hex editor, it's just really a terrible idea. You might corrupt it in ways that Git does not expect. The end result is that it no longer works as you want, and the only reason for that is that you edited the file manually, and you messed up.

It's the same, really, when you edit the .git-credentials file. You have to abide by the format Git expects. And if you save with CR/LF line endings, well, there you go, you messed up, the file is no longer in a format Git handles because it did not expect you to mess it up. It expected that file to be under its own control. And you broke that contract.

I don't think that it is a good idea to change Git in a way that it tries to work around such mess-ups. That would just set this awful precedent where I have to spend even more time on addressing problems that aren't caused by bugs in Git, but purely by users doing something that they shouldn't have done in the first place, because it's outside of what is supported.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@dscho : I understand and respect your point of view. I appreciate you taking the time to review my request and discuss it with me. Feel free to close this pull request and close the issue as well.

printf "https://user:pass@example.com\r\n" >"$HOME/.git-credentials" &&
check fill store <<-\EOF
protocol=https
host=example.com
--
protocol=https
host=example.com
username=askpass-username
password=askpass-password
--
askpass: Username for '\''https://example.com'\'':
askpass: Password for '\''https://askpass-username@example.com'\'':
username=user
password=pass
--
EOF
'
Expand All @@ -173,7 +170,7 @@ test_expect_success 'get: credentials with path and DOS line endings are valid'
EOF
'

test_expect_success 'get: credentials with DOS line endings are invalid if path is relevant' '
test_expect_success 'get: credentials with DOS line endings are valid if path is relevant' '
printf "https://user:pass@example.com/repo.git\r\n" >"$HOME/.git-credentials" &&
test_config credential.useHttpPath true &&
check fill store <<-\EOF
Expand All @@ -182,11 +179,8 @@ test_expect_success 'get: credentials with DOS line endings are invalid if path
protocol=https
host=example.com
path=repo.git
username=askpass-username
password=askpass-password
--
askpass: Username for '\''https://example.com/repo.git'\'':
askpass: Password for '\''https://askpass-username@example.com/repo.git'\'':
username=user
password=pass
--
EOF
'
Expand Down
Loading