foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.17k stars 1.7k forks source link

Remove git config --global requirements from forge #4215

Open activate-glacier-instinct opened 1 year ago

activate-glacier-instinct commented 1 year ago

Component

Forge

Describe the feature you would like

Being able to run forge init on a system that does not have global git settings configured.

Requested behaviour

  1. Test git settings
git config --list | grep 'user.'       // Outputs nothing
  1. Forge init
forge init hello_foundry             // Creates the project

Current behaviour

  1. Test git settings
git config --list | grep 'user.'       // Outputs nothing
  1. Forge init
forge init hello_foundry    

Output:

Initializing /home/USER/foundry/hello_foundry...
Error: 
Author identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect e-mail address (got 'USER')

Additional context

Background Most of my crypto work is anon, so I don't globally set my git credentials. I set them up per repo using scripts.

This is the reason why I'm running the above command in an empty folder.

Setting up a foundry project within a pre-initialised repo also doesn't work. More on that here: https://github.com/foundry-rs/foundry/issues/4214

DaniPopes commented 1 year ago

I'm assuming this error occurs when we try to commit, and since there are no local or global credentials the commit command fails. Can you please retry with the --no-commit flag, or by setting email environment variable (EMAIL="..." forge init ..., commit author name defaults to the system user/hostname)?

activate-glacier-instinct commented 1 year ago

A. forge init {PROJECT_NAME} --no-commit was a pass for me.

For reference I created the project in an projects directory on a system with no global git configs.

1, Check git config

git config --list | grep 'user.'           // Outputs nothing
  1. Location folder
ls                                                  // Outputs folders within the, ie. not an empty folder 
  1. Forge init
forge init hello_foundry --no-commit  // Creates the project as expected
  1. Check the project creation
ls                                                       // contains `hello_foundry` folder

=======

B. forge init --template {TEMPLATE} {PROJECT_NAME} --no-commit was a fail

I also wanted to test project creation from a template. Feels like most users would want to use this scaffolding.

Got the following error

error: the argument '--template <TEMPLATE>' cannot be used with '--no-commit'

Usage: forge init --template <TEMPLATE> <ROOT>

For more information, try '--help'.

=======

C. Comments

When purely looking at forge-init as a project scaffolding tool, the committing of the scaffold seems odd.

I'm comparing it to other large scaffolding tools: create-react-app (98.7k stars on Github)

For example create-react-app doesn't init the repo for the user:

0.1 Pre-requisites

  1. Run the create-react-app
npx create-react-app test-react
  1. List the created folder
ls test-react                                       // Outputs project files
  1. Check the project repo
cd test-react && git status 

Outputs:


fatal: not a git repository (or any of the parent directories): .git

``

=======

D. Thank you

Thanks a lot @DaniPopes I can move forward with the `--no-commit` workaround.
DaniPopes commented 1 year ago

A. great, I guess we could make the error clearer for future users

B. that's definitely a bug, easy fix for anyone to implement: just remove the "conflicts" in the clap args and put the template commit under an if block

C. It really depends on the framework as well. Rust projects initialized with Cargo also start with a vcs (like git). But also this is nice for Foundry since we are still using git submodules as dependencies