Skip to contentSkip to conversation

Multiline value should error if the next line is section

bug Shulhan 4 participants 5 messages May 6, 2018

lore
Share & tools
lore

Shulhan

author
#0 lore raw

## Environment

OS: Arch Linux
Git version: git@next d54016d9e

## Reproduction Steps

(1) Create the following git.config,

```
[alias]
        tree = --no-pager log --graph \
                --date=format:'%Y-%m-%d' \
                --pretty=format:'%C(auto,dim)%ad %<(7,trunc) %an %Creset%m %h %s %Cgreen%d%Creset' \
                --exclude="*/production" \
                --exclude="*/dev-*" \
                -n 20 \
[user]
        name = Shulhan
        email = [email protected]
```

(2) Run git config -f git.config -l

## Expected Result

Error message,

fatal: bad config line 9 at git.config

## Actual Result

The command print the following output,

```
alias.tree=--no-pager log --graph
--date=format:'%Y-%m-%d'
--pretty=format:'%C(auto,dim)%ad %<(7,trunc) %an %Creset%m %h %s %Cgreen%d%Creset' --exclude=*/production                 --exclude=*/dev-*                 -n 20 [user]
alias.name=Shulhan
[email protected]
```
#1 lore raw

Hi Shulhan

Thank you for your report. I'm abbreviating a bit:

Quoted 6 lines · Shulhan

[alias]

        tree = --no-pager log --graph \
                -n 20 \

[user]
name = Shulhan

Quoted 6 lines

(2) Run git config -f git.config -l

The command print the following output,

alias.tree=--no-pager log --graph -n 20 [user]
alias.name=Shulhan

Small mistake, big consequences. :-)

This behavior looks correct to me, though. It seems very hard to me to second-guess what the user meant. For example, what if that third line contained a "="? Like:

[alias]

        huh = !dd \
              bs=1024 ...

Should Git guess that the backslash on the second line was a mistake? Or maybe not, because alias.bs = "1024 ..." would be a useless alias?

I think such guessing would be theoretically possible, but especially if Git guesses wrong, that could be very frustrating to fight against.

Martin

#2 lore raw
Quoted 5 lines · Martin Ågren

This behavior looks correct to me, though. It seems very hard to me to second-guess what the user meant. For example, what if that third line contained a "="? Like:

[alias]

Quoted 8 lines
        huh = !dd \
              bs=1024 ...

Should Git guess that the backslash on the second line was a mistake? Or maybe not, because alias.bs = "1024 ..." would be a useless alias?

I think such guessing would be theoretically possible, but especially if Git guesses wrong, that could be very frustrating to fight against.

I agree that trying to guess what the user wanted here is likely impossible.

Furthermore, Git intentionally ignores unknown options. For example, I have advice and diff options set in my .gitconfig that would not be valid on the Git shipped with a base CentOS 6 (which, unfortunately, I sometimes have to use). It's very convenient for users working across a variety of systems that unknown options are simply ignored, even if that means sometimes mistakes are not caught.

Signature · 2 lines
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
author
#3 lore raw
In reply to Martin Ågren
Quoted 24 lines · On Sun, 6 May 2018 22:03:10 +0200 Martin Ågren <[email protected]> wrote:

Hi Shulhan

Thank you for your report. I'm abbreviating a bit:

Quoted 6 lines · Shulhan

[alias]

        tree = --no-pager log --graph \
                -n 20 \

[user]
name = Shulhan

Quoted 6 lines

(2) Run git config -f git.config -l

The command print the following output,

alias.tree=--no-pager log --graph -n 20 [user]
alias.name=Shulhan

Small mistake, big consequences. :-)

This behavior looks correct to me, though. It seems very hard to me to second-guess what the user meant. For example, what if that third line contained a "="? Like:

Quoted 6 lines

[alias]

        huh = !dd \
              bs=1024 ...

Should Git guess that the backslash on the second line was a mistake? Or maybe not, because alias.bs = "1024 ..." would be a useless alias?

The context of multiline next value that I reported before was about section, not variable.

Quoted 4 lines

I think such guessing would be theoretically possible, but especially if Git guesses wrong, that could be very frustrating to fight against.

I'm not familiar with git config parser, obviously :), but checking the start of next multiline value that start with '[' maybe not impossible. Git should not guessed, but report error at the offending line: either user forgot to enclosed the variable with double quote or they missplace the backslash.

#4 lore raw
Quoted 38 lines
Quoted 20 lines · On Sun, 6 May 2018 22:03:10 +0200 Martin Ågren <[email protected]> wrote:
Quoted 6 lines · Shulhan

[alias]

        tree = --no-pager log --graph \
                -n 20 \

[user]
name = Shulhan

Quoted 6 lines

(2) Run git config -f git.config -l

The command print the following output,

alias.tree=--no-pager log --graph -n 20 [user]
alias.name=Shulhan

Small mistake, big consequences. :-)

This behavior looks correct to me, though. It seems very hard to me to second-guess what the user meant. For example, what if that third line contained a "="? Like:

Quoted 6 lines

[alias]

        huh = !dd \
              bs=1024 ...

Should Git guess that the backslash on the second line was a mistake? Or maybe not, because alias.bs = "1024 ..." would be a useless alias?

The context of multiline next value that I reported before was about section, not variable.

Quoted 4 lines

I think such guessing would be theoretically possible, but especially if Git guesses wrong, that could be very frustrating to fight against.

Quoted 5 lines

I'm not familiar with git config parser, obviously :), but checking the start of next multiline value that start with '[' maybe not impossible. Git should not guessed, but report error at the offending line: either user forgot to enclosed the variable with double quote or they missplace the backslash.

But it's not an error; as far as the config file syntax is concerned, it's perfectly valid, even if it's not what you intended. Reporting it as error would be just guessing.