opam icon indicating copy to clipboard operation
opam copied to clipboard

opam pin fails on Windows

Open cometkim opened this issue 7 months ago • 6 comments

I trying to pin a package to a specific commit hash

opam pin add flow_parser git+https://github.com/rescript-lang/flow.git#d35a6f5c0cc219e85bbcb822d6f19ed9b2ec3448

This works well on my Linux/MacOS machine. But fails on Windows (GitHub actions)

opam pin add flow_parser https://github.com/rescript-lang/flow.git#d35a6f5c0cc219e85bbcb822d6f19ed9b2ec3448
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
Error:  Could not synchronize C:\Users\runneradmin\AppData\Local\opam\default\.opam-switch\sources\flow_parser from "git+https://github.com/rescript-lang/flow.git#d[3](https://github.com/cometkim/windows-action-test/actions/runs/14424847341/job/40452212688#step:6:3)5a6f5c0cc219e85bbcb822d6f19ed9b2ec3448":
        Git error: refs/remotes/opam-ref-d35a6f5c0cc219e85bbcb822d6f19ed9b2ec3[4](https://github.com/cometkim/windows-action-test/actions/runs/14424847341/job/40452212688#step:6:5)48 not found.
Error:  Error getting source from git+https://github.com/rescript-lang/flow.git#d35a6f5c0cc219e85bbcb822d6f19ed9b2ec3448:
          - git+https://github.com/rescript-lang/flow.git#d35a6f5c0cc219e85bbcb822d6f19ed9b2ec3448
[flow_parser.0.246.0] fetching sources failed: git+https://github.com/rescript-lang/flow.git#d3[5](https://github.com/cometkim/windows-action-test/actions/runs/14424847341/job/40452212688#step:6:6)a6f5c0cc219e85bbcb822d6f19ed9b2ec3448

https://github.com/cometkim/windows-action-test/actions/runs/14424847341/job/40452212688

cometkim avatar Apr 13 '25 01:04 cometkim

It's unfortunately obvious what's wrong when looking at the debug output:

+ C:\Program Files\Git\cmd\git.exe "reset" "--hard" "refs/remotes/opam-ref-d35a6f5c0cc219e85bbcb822d6f19ed9b2ec3448" "--" (CWD=C:\Users\DRA\AppData\Local\opam\issue6472\.opam-switch\sources\flow_parser)
fatal: cannot create directory at 'tests/long_directory_names/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path': Filename too long

dra27 avatar Apr 14 '25 12:04 dra27

I don't think this has anything to do with pinning a sha - the issue is the path at https://github.com/rescript-lang/flow/tree/rescript/tests/long_directory_names/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path.

The fix here needs to be in the repo - committing a path that long is a bit like including non-Windows characters (e.g. filenames with : in them). I'd suggest it'd be better to generate that long path in the test harness

The repo is just cloneable on Windows - it's just that the opam root and where the repo is then cloned to makes it too long.

dra27 avatar Apr 14 '25 12:04 dra27

We should probably surface the error message from Git more clearly, though!

dra27 avatar Apr 14 '25 12:04 dra27

Huh, I never expected that long path in the flow repository. Thank you for pointing it out!

cometkim avatar Apr 14 '25 14:04 cometkim

Maybe it is dangerous for Windows users that opam enables core.longpaths=true in the current shell/project? Or it would be better if it at least prints a warning about it.

cometkim avatar Apr 14 '25 14:04 cometkim

It's the same problem during the install process. This is the only error message I got

#=== ERROR while compiling flow_parser.0.267.0 ================================#
C:\hostedtoolcache\windows\opam\2.3.0\x86_64\opam.exe: "opendir" failed: No such file or directory

This has been resolved by removing the problematic directory.

I think it happened while scanning the dune file by dune build, which is configured as build: in the opam's manifest.

cometkim avatar Apr 14 '25 15:04 cometkim