Skip to content
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

cabal init doesn't autodetect author name and maintainer email #8255

Closed
fgaz opened this issue Jun 25, 2022 · 6 comments · Fixed by #8267
Closed

cabal init doesn't autodetect author name and maintainer email #8255

fgaz opened this issue Jun 25, 2022 · 6 comments · Fixed by #8267
Labels
cabal-install: cmd/init regression on master Regression that is unreleased and needs to be fixed before release type: bug type: regression

Comments

@fgaz
Copy link
Member

fgaz commented Jun 25, 2022

Describe the bug

cabal init doesn't autodetect author name and maintainer email. the old init implementation did, and i found it pretty useful

To Reproduce
Steps to reproduce the behavior:

$ cabal init
[...]
Author name? [optional] 
Maintainer email? [optional] 
[...]

Expected behavior
A clear and concise description of what you expected to happen.

[...]
Author name? [default: Name Surname] 
Maintainer email? [default: user@example.com]
[...]

(detected from git iirc)

System information

  • cabal HEAD
  • NixOS, but my git config is in the usual place

Additional context
Add any other context about the problem here.

cc @ptkato @emilypi

@fgaz fgaz added type: bug cabal-install: cmd/init type: regression regression on master Regression that is unreleased and needs to be fixed before release labels Jun 25, 2022
@ptkato
Copy link
Collaborator

ptkato commented Jun 25, 2022

It should? Previously it used git, darcs and some weird env flags to try to guess the name/email, now it only uses git.

-- | Guess author and email using git configuration options.
guessAuthorName :: Interactive m => m String
guessAuthorName = guessGitInfo "user.name"
guessAuthorEmail :: Interactive m => m String
guessAuthorEmail = guessGitInfo "user.email"
guessGitInfo :: Interactive m => String -> m String
guessGitInfo target = do
info <- readProcessWithExitCode "git" ["config", "--local", target] ""
if null $ snd' info
then trim . snd' <$> readProcessWithExitCode "git" ["config", "--global", target] ""
else return . trim $ snd' info
where
snd' (_, x, _) = x

@fgaz
Copy link
Member Author

fgaz commented Jun 25, 2022

Calling those functions in the repl correctly shows my info. Weird! Maybe that information doesn't actually get used as default?

λ import Distribution.Client.Init.NonInteractive.Heuristics 
λ guessAuthorName 
"Francesco Gazzetta"

@fgaz
Copy link
Member Author

fgaz commented Jun 25, 2022

cabal init -n works. my guess is that the empty input in the interactive init gets interpreted as Flag "" instead of NoFlag and overrides the Flag "Name from git" when mappended

@fgaz
Copy link
Member Author

fgaz commented Jun 25, 2022

Also it'd be nice to display [default: ...] like old init

@Mikolaj Mikolaj added this to the Considered for 3.8 milestone Jun 27, 2022
@Mikolaj
Copy link
Member

Mikolaj commented Jul 4, 2022

Hi! So what's the status of this ticket (and #8236 and #8206)? We may be releasing 3.8 in a week or two (and a major highlight is the new shiny cabal init) so there's still time to polish any remaining snags.

@ulysses4ever
Copy link
Collaborator

@Mikolaj at least this one should be fixed in #8267

ulysses4ever added a commit to ulysses4ever/cabal that referenced this issue Jul 8, 2022
…askell#8255)

Name and email are fetched from git config in the non-interactive init
already, and we plug that utility into the interactive one in this commit.

Testing becomes clunkier: the list of inputs have to hold an additional
string that will be used as the return value of
`Interactive.readProcessWithExitCode`, and here is why. Recall that this
method is used to call `git config` to perform autodetection. In the
real scenario (the `IO` instance of `Interactive`), it actually calls
out to `git`. In the testing scenario (the `PurePrompt` instance of
`Interactive`), the method simply returns the next element of the list
of pre-defined inputs. So, the list of inputs to every relevant test has
to be adjusted.
ulysses4ever added a commit to ulysses4ever/cabal that referenced this issue Jul 8, 2022
…askell#8255)

Name and email are fetched from git config in the non-interactive init
already, and we plug that utility into the interactive one in this commit.

Testing becomes clunkier: the list of inputs have to hold an additional
string that will be used as the return value of
`Interactive.readProcessWithExitCode`, and here is why. Recall that this
method is used to call `git config` to perform autodetection. In the
real scenario (the `IO` instance of `Interactive`), it actually calls
out to `git`. In the testing scenario (the `PurePrompt` instance of
`Interactive`), the method simply returns the next element of the list
of pre-defined inputs. So, the list of inputs to every relevant test has
to be adjusted.
@mergify mergify bot closed this as completed in #8267 Jul 8, 2022
mergify bot pushed a commit that referenced this issue Jul 8, 2022
* cabal init -i should autodetect author name and maintainer email (fix #8255)

Name and email are fetched from git config in the non-interactive init
already, and we plug that utility into the interactive one in this commit.

Testing becomes clunkier: the list of inputs have to hold an additional
string that will be used as the return value of
`Interactive.readProcessWithExitCode`, and here is why. Recall that this
method is used to call `git config` to perform autodetection. In the
real scenario (the `IO` instance of `Interactive`), it actually calls
out to `git`. In the testing scenario (the `PurePrompt` instance of
`Interactive`), the method simply returns the next element of the list
of pre-defined inputs. So, the list of inputs to every relevant test has
to be adjusted.

* Add test checking that username/email can be autodetected
mergify bot pushed a commit that referenced this issue Jul 8, 2022
* cabal init -i should autodetect author name and maintainer email (fix #8255)

Name and email are fetched from git config in the non-interactive init
already, and we plug that utility into the interactive one in this commit.

Testing becomes clunkier: the list of inputs have to hold an additional
string that will be used as the return value of
`Interactive.readProcessWithExitCode`, and here is why. Recall that this
method is used to call `git config` to perform autodetection. In the
real scenario (the `IO` instance of `Interactive`), it actually calls
out to `git`. In the testing scenario (the `PurePrompt` instance of
`Interactive`), the method simply returns the next element of the list
of pre-defined inputs. So, the list of inputs to every relevant test has
to be adjusted.

* Add test checking that username/email can be autodetected

(cherry picked from commit 1b8bf8c)
andreabedini pushed a commit that referenced this issue Jul 8, 2022
* cabal init -i should autodetect author name and maintainer email (fix #8255)

Name and email are fetched from git config in the non-interactive init
already, and we plug that utility into the interactive one in this commit.

Testing becomes clunkier: the list of inputs have to hold an additional
string that will be used as the return value of
`Interactive.readProcessWithExitCode`, and here is why. Recall that this
method is used to call `git config` to perform autodetection. In the
real scenario (the `IO` instance of `Interactive`), it actually calls
out to `git`. In the testing scenario (the `PurePrompt` instance of
`Interactive`), the method simply returns the next element of the list
of pre-defined inputs. So, the list of inputs to every relevant test has
to be adjusted.

* Add test checking that username/email can be autodetected

(cherry picked from commit 1b8bf8c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cabal-install: cmd/init regression on master Regression that is unreleased and needs to be fixed before release type: bug type: regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants