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.33k stars 1.76k forks source link

Bug: forge does not add tag information into gitmodules file on install #7225

Open sambacha opened 9 months ago

sambacha commented 9 months ago

Component

Forge

Have you ensured that all of these are up to date?

What version of Foundry are you on?

forge 0.2.0 (a436a0d 2024-02-20T00:25:57.253479000Z) && forge 0.2.0 (6d5de51 2024-02-23T00:19:38.512335000Z)

What command(s) is the bug in?

forge install

Operating System

macOS (Apple Silicon)

Describe the bug

Running this install, solidstate-network/solidstate-solidity@v0.0.59

$  forge install solidstate-network/solidstate-solidity@v0.0.59
Installing solidstate-solidity in /Users/janitor/rico/lib/solidstate-solidity (url: Some("https://github.com/solidstate-network/solidstate-solidity"), tag: Some("v0.0.59"))
Cloning into '/Users/janitor/rico/lib/solidstate-solidity'...
remote: Enumerating objects: 17261, done.
remote: Counting objects: 100% (3206/3206), done.
remote: Compressing objects: 100% (671/671), done.
remote: Total 17261 (delta 2572), reused 3007 (delta 2506), pack-reused 14055
Receiving objects: 100% (17261/17261), 4.06 MiB | 5.31 MiB/s, done.
Resolving deltas: 100% (12427/12427), done.
    Installed solidstate-solidity v0.0.59

After we inspect .gitmodules and find

[submodule "lib/solidstate-solidity"]
        path = lib/solidstate-solidity
        url = https://github.com/solidstate-network/solidstate-solidity

However we want the .gitmodules file to reflect this correct configuration

[submodule "lib/solidstate-solidity"]
        path = lib/solidstate-solidity
        url = https://github.com/solidstate-network/solidstate-solidity
+       branch = v0.0.59
sambacha commented 9 months ago

Confirmed just in case

$ forge install foundry-rs/forge-std@v1.7.6  
Installing forge-std in /Users/janitor/tstorish/lib/forge-std (url: Some("https://github.com/foundry-rs/forge-std"), tag: Some("v1.7.6"))  
Cloning into '/Users/janitor/tstorish/lib/forge-std'...  
remote: Enumerating objects: 2168, done.  
remote: Counting objects: 100% (2164/2164), done.  
remote: Compressing objects: 100% (722/722), done.  
remote: Total 2168 (delta 1436), reused 2070 (delta 1375), pack-reused 4  
Receiving objects: 100% (2168/2168), 610.57 KiB | 2.81 MiB/s, done.  
Resolving deltas: 100% (1436/1436), done.  
Submodule 'lib/ds-test' (https://github.com/dapphub/ds-test) registered for path 'lib/ds-test'  
Cloning into '/Users/janitor/tstorish/lib/forge-std/lib/ds-test'...  
remote: Enumerating objects: 313, done.  
remote: Counting objects: 100% (171/171), done.  
remote: Compressing objects: 100% (79/79), done.  
remote: Total 313 (delta 91), reused 132 (delta 83), pack-reused 142  
Receiving objects: 100% (313/313), 71.35 KiB | 1.32 MiB/s, done.  
Resolving deltas: 100% (130/130), done.  
   Installed forge-std v1.7.6  
01:59:55 Sat Feb 24 2024 janitor macbook /Users/janitor/tstorish feat/simple-tests
$ cat .gitmodules
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
klkvr commented 9 months ago

branch field can only contain a branch name in the specified repository, not a tag name.

Currently when installing submodule, forge tries to find a branch with the same name as the tag, and only if it's found, the branch field is populated

https://github.com/foundry-rs/foundry/blob/474591aa1e6922a0d5691ae1e2dcc355d8fcb92d/crates/forge/bin/cmd/install.rs#L345-L350

sambacha commented 9 months ago

branch field can only contain a branch name in the specified repository, not a tag name.

Currently when installing submodule, forge tries to find a branch with the same name as the tag, and only if it's found, the branch field is populated

https://github.com/foundry-rs/foundry/blob/474591aa1e6922a0d5691ae1e2dcc355d8fcb92d/crates/forge/bin/cmd/install.rs#L345-L350


$ forge install -h  
Install one or multiple dependencies

Usage: forge install \[OPTIONS\] \[DEPENDENCIES\]...  
   forge install \[OPTIONS\] \<github username>/\<github project>@\<tag>...  
   forge install \[OPTIONS\] \<alias>=\<github username>/\<github project>@\<tag>...  
   forge install \[OPTIONS\] \<https:// git url>...

$ forge install /transmissions11/solmate@c892309933b25c03d32b1b0d674df7ae292ba925

Resolving deltas: 100% (130/130), done.  
   Installed solmate c892309933b25c03d32b1b0d674df7ae292ba925  
08:11:40 Mon Feb 26 2024 janitor macbook /Users/janitor/solmate-tmp master  
$ cat .gitmodules  
\[submodule "lib/forge-std"\]  
path = lib/forge-std  
url = https://github.com/foundry-rs/forge-std  
\[submodule "lib/solmate"\]  
path = lib/solmate  
url = [https://github.com//transmissions11/solmate](https://github.com//transmissions11/solmate)

Forge uses 'tag' to mean any git commit hash, the behaviour is true in that regard. As you mention git submodules does not explicitly support proper git tags, however this is just really an alias for some git commit hash really.

zerosnacks commented 4 months ago

Hi @sambacha, thanks for reporting this

Confirming this issue is still active (cc @klkvr)

I've created a minimal reproduction here: https://github.com/zerosnacks/foundry-bug-7225-repro that has a practical example people run into relating to the 0.8 branch of Uniswap V3 + forge update.

zerosnacks commented 1 month ago

Ref: https://github.com/foundry-rs/foundry/issues/3720

grandizzy commented 4 weeks ago

we're going to add --branch/--tag args with https://github.com/foundry-rs/foundry/issues/5996 and then use them to pin it to specific branch.