foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Remove git config --global requirements from forge

Open activate-glacier-instinct opened this issue 2 years ago • 4 comments

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 "[email protected]"
  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

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)?

DaniPopes avatar Jan 29 '23 20:01 DaniPopes

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

  • Requires node to be installed on the system, best installed via nvm
  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.

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

DaniPopes avatar Jan 30 '23 08:01 DaniPopes

For future reference:

forge init --template https://github.com/foundry-rs/forge-template --no-commit does not respect the --no-commit flag

zerosnacks avatar Oct 15 '24 11:10 zerosnacks