src-cli icon indicating copy to clipboard operation
src-cli copied to clipboard

File Name Too Long Error On Windows PowerShell 7

Open alexAtSourcegraph opened this issue 1 year ago • 2 comments

fatal: unable to stat ‘path/to/files’ Filename too long: exit status 128 error when repos have long names.

Effort tried to rectify issue:

  • setting git config –system core.longpaths to true
  • enabling long paths in Windows

alexAtSourcegraph avatar Oct 03 '22 17:10 alexAtSourcegraph

Hi @alexAtSourcegraph !

I had the same issue as you using Git for Windows and Git bash in Windows 10:

manios@LAPTOP-WIN10 MINGW64 /c/goprojects/src-cli/cmd/src (main)
$ ./src.exe batch preview -f ../../deleteean.yml
✅ Parsing batch spec
✅ Resolving namespace
✅ Preparing container images  ███████████████████  100%✅ Set workspace type
✅ Resolved 1 workspaces from 1 repositories
✅ Found 0 cached changeset specs; 1 task needs to be executed
✅ Executing... (1/1, 1 errored)  ███████ 100%│
└── gitlab.internal.manios.local/maniosorg/myprojects/jetfirestarter  creating workspace: preparing local git repo: git add failed: 'git add --force --all' failed: warning: could not open directory 'src/test/java/org/manios/jfs/service/impl...  0s
❌ Error:
   gitlab.internal.manios.local/maniosorg/myprojects/jetfirestarter:
   creating workspace: preparing local git repo: git add failed: 'git add --force --all' failed: warning: could not open directory 'src/test/java/org/manios/jfs/service/impl': Filename too long
   fatal: unable to stat 'src/main/java/org/manios/jfs/service/impl/FirestarterImpl.java': Filename too long: exit status 128
   Log: C:\Users\manios\AppData\Local\Temp\changeset-gitlab.internal.manios.local.maniosorg.jetfirestarter-01c9cda30fb8dcd2701303efc5d2e6e65218d952.2041328270.log

The problem is that src-cli is configured to ignore your internal Git configuration. Therefore setting git config -system core.longpaths to true will be ignored.

The only way to make it work is to patch locally the internal\batches\workspace\git.go as :

diff --git a/internal/batches/workspace/git.go b/internal/batches/workspace/git.go
index 20c20d1..ef409b2 100644
--- a/internal/batches/workspace/git.go
+++ b/internal/batches/workspace/git.go
@@ -12,9 +12,9 @@ func runGitCmd(ctx context.Context, dir string, args ...string) ([]byte, error)
        cmd := exec.CommandContext(ctx, "git", args...)
        cmd.Env = []string{
                // Don't use the system wide git config.
-               "GIT_CONFIG_NOSYSTEM=1",
+               // "GIT_CONFIG_NOSYSTEM=1",
                // And also not any other, because they can mess up output, change defaults, .. which can do unexpected things.
-               "GIT_CONFIG=/dev/null",
+               // "GIT_CONFIG=/dev/null",
                // Don't ask interactively for credentials.
                "GIT_TERMINAL_PROMPT=0",
                // Set user.name and user.email in the local repository. The user name and

Then, if you compile it locally and run it, it works. I could not find any other straightforward solution at the moment.

Best regards, Christos

manios avatar Dec 14 '22 09:12 manios