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

Return empty default when git fails #8755

Merged
merged 2 commits into from
Mar 5, 2023
Merged

Conversation

BasLaa
Copy link
Collaborator

@BasLaa BasLaa commented Feb 12, 2023

As mentioned in #8478, cabal init throws an error when git is not installed as it fails to guess a default name and email for the user. Instead, it should give an empty default (or no default perhaps?) and perhaps a note.

@BasLaa
Copy link
Collaborator Author

BasLaa commented Feb 12, 2023

I was thinking we could do a check in authorPrompt and emailPrompt in Client.init.Interactive.Command to see if the returned guess is empty. If it's empty, we can pass the MandatoryPrompt flag instead of DefaultPrompt ...?

@BasLaa
Copy link
Collaborator Author

BasLaa commented Feb 13, 2023

In the function authorHeuristics, the guessAuthorEmail is used whereas in emailHeuristics, the guessAuthorName function is used. I left it in this way for now, but this seems like a mistake and they should be the other way around?

@BasLaa
Copy link
Collaborator Author

BasLaa commented Feb 15, 2023

I'm having trouble understanding what is going wrong exactly in the unit test. It seems to me that running getAuthor flags $ return "" should prompt the user, which I think would be the desired behaviour when there is no flag and we cannot guess using git.

@ffaf1
Copy link
Collaborator

ffaf1 commented Feb 15, 2023

I suspect the tests mock system calls, like

inputs = NEL.fromList
-- extra sources
[ "[\"CHANGELOG.md\"]"
-- lib other modules
, "False"
-- exe other modules
, "False"
-- test main file
, "True"
, "[\"quxTest/Main.hs\"]"
-- test other modules
, "False"
]

should be changed. a63fe9b (#7344) shows a previous adjustment, but I am not sure how to read those. There is this Interactive instance at play:

instance Interactive PurePrompt where
getLine = pop
readFile !_ = pop
getCurrentDirectory = popAbsolute
getHomeDirectory = popAbsolute
-- expects stack input of form "[\"foo\", \"bar\", \"baz\"]"
getDirectoryContents !_ = popList
listDirectory !_ = popList
doesDirectoryExist !_ = popBool
doesFileExist !_ = popBool
canonicalizePathNoThrow !_ = popAbsolute
readProcessWithExitCode !_ !_ !_ = do
input <- pop
return (ExitSuccess, input, "")
getEnvironment = fmap (map read) popList
getCurrentYear = fmap read pop
listFilesInside pred' !_ = do
input <- map splitDirectories <$> popList
map joinPath <$> filterM (fmap and . traverse pred') input
listFilesRecursive !_ = popList
putStr !_ = return ()
putStrLn !_ = return ()
createDirectory !d = checkInvalidPath d ()
removeDirectory !d = checkInvalidPath d ()
writeFile !f !_ = checkInvalidPath f ()
removeExistingFile !f = checkInvalidPath f ()
copyFile !f !_ = checkInvalidPath f ()
renameDirectory !d !_ = checkInvalidPath d ()
hFlush _ = return ()
message !_ !severity !msg = case severity of
Error -> PurePrompt $ \_ -> Left $ BreakException
(show severity ++ ": " ++ msg)
_ -> return ()

One of the popList calls is the offending one.

@BasLaa
Copy link
Collaborator Author

BasLaa commented Feb 16, 2023

I changed the unit test to include inputs, let's see what works

@BasLaa
Copy link
Collaborator Author

BasLaa commented Feb 17, 2023

Everything seems to be working, I'm just wondering how to write a separate test for this. Testing this behaviour is dependent on whether the test environment has git installed. I would assume that since all the tests passed before this change, git was in the test environment. Is there a way to run a test without git installed to see if the behaviour works?

@BasLaa BasLaa marked this pull request as ready for review February 22, 2023 06:32
@BasLaa
Copy link
Collaborator Author

BasLaa commented Feb 25, 2023

Is there someone who could take a look at this?

Copy link
Collaborator

@ulysses4ever ulysses4ever left a comment

Choose a reason for hiding this comment

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

Thank you!

@ulysses4ever
Copy link
Collaborator

@ffaf1 your comments seem to be stressed. Do you want to OK this one?

As a bug fix, I think we should try to squeeze it in 3.10. Most egregious is Maintainer and Author fields were swapped under cabal init -n.

Copy link
Collaborator

@ffaf1 ffaf1 left a comment

Choose a reason for hiding this comment

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

good job!

@ulysses4ever
Copy link
Collaborator

ulysses4ever commented Mar 1, 2023

@ffaf1 thank you!

@BasLaa could you please put the label on. Either squash+merge if you leave the history as is, or merge-me if you want to cleanup the history manually. The latter may make sense to have the author-email fixup separately.

@BasLaa
Copy link
Collaborator Author

BasLaa commented Mar 1, 2023

@ulysses4ever I would be happy to separate the fixes, I'm just not sure how to do that. Should I make two separate new PRs with the changes in each?

@ffaf1
Copy link
Collaborator

ffaf1 commented Mar 1, 2023

No he means separate commits. Rebase on your machine to a history that you like and force push.

@ulysses4ever
Copy link
Collaborator

ulysses4ever commented Mar 1, 2023

Yes, Francesco is right: that's what I meant. You'd need to rebase interactively and then force-push.

@BasLaa
Copy link
Collaborator Author

BasLaa commented Mar 1, 2023

I think I did it correctly? Only changing the first commit message didn't go as I'd hoped.

@BasLaa BasLaa added the merge me Tell Mergify Bot to merge label Mar 1, 2023
@ulysses4ever
Copy link
Collaborator

@BasLaa looks good, thank you!

@mergify mergify bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Mar 3, 2023
@mergify
Copy link
Contributor

mergify bot commented Mar 3, 2023

⚠️ This pull request got rebased on behalf of a random user of the organization.
This behavior will change on the 1st February 2023, Mergify will pick the author of the pull request instead.

To get the future behavior now, you can configure bot_account options (e.g.: bot_account: { author } or update_bot_account: { author }.

Or you can create a dedicated github account for squash and rebase operations, and use it in different bot_account options.

@BasLaa
Copy link
Collaborator Author

BasLaa commented Mar 5, 2023

Something seems to have gone wrong with merging here, a test failed for some reason?

@ffaf1
Copy link
Collaborator

ffaf1 commented Mar 5, 2023

Force push, sometimes CI is finicky.

BasLaa added 2 commits March 5, 2023 14:41
Add maybe in guess functions

Adjust type in NonInteractive

Change unit tests

Fix whitespace

Abstract guessing and remove comments

Simplify guess functions

Return default for cabal init author and name when git fails
@haskell haskell deleted a comment from mergify bot Mar 5, 2023
@mergify mergify bot merged commit 0f51816 into haskell:master Mar 5, 2023
@Kleidukos
Copy link
Member

@Mergifyio backport 3.10

@mergify
Copy link
Contributor

mergify bot commented Jun 17, 2023

backport 3.10

✅ Backports have been created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
attention: needs-review merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days merge me Tell Mergify Bot to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants