jlewi / hydros

hydros automates hydrating and committing configuration
Apache License 2.0
4 stars 0 forks source link

Error opening repository that already exists #98

Closed jlewi closed 3 days ago

jlewi commented 4 months ago

Rerunning a build the directory is already checked out but it can't be opened.

2024-04-17T15:21:38.080-0700    ERROR   app/app.go:158  Apply failed    {"path": "releasing.yaml", "error": "Could not open respoistory at /tmp/hydros_work_dir/github.com/jlewi/foyle; ensure the directory contains a git repo: repository does not exist", "errorVerbose": "repository does not exist\nCould not open respoistory at /tmp/hydros_work_dir/github.com/jlewi/foyle; ensure the directory contains a git repo\ngithub.com/jlewi/hydros/pkg/github.(*ReposCloner).cloneRepo\n\t/Users/jlewi/git_hydros/pkg/github/clone.go:139\ngithub.com/jlewi/hydros/pkg/github.(*ReposCloner).Run\n\t/Users/jlewi/git_hydros/pkg/github/clone.go:35\ngithub.com/jlewi/hydros/pkg/gitops.(*RepoController).Reconcile\n\t/Users/jlewi/git_hydros/pkg/gitops/repocontroller.go:102\ngithub.com/jlewi/hydros/pkg/app.(*App).apply\n\t/Users/jlewi/git_hydros/pkg/app/app.go:257\ngithub.com/jlewi/hydros/pkg/app.(*App).ApplyPaths\n\t/Users/jlewi/git_hydros/pkg/app/app.go:156\ngithub.com/jlewi/hydros/cmd/commands.NewApplyCmd.func1.1\n\t/Users/jlewi/git_hydros/cmd/commands/apply.go:55\ngithub.com/jlewi/hydros/cmd/commands.NewApplyCmd.func1\n\t/Users/jlewi/git_hydros/cmd/commands/apply.go:56\ngithub.com/spf13/cobra.(*Command).execute\n\t/Users/jlewi/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:944\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\t/Users/jlewi/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068\ngithub.com/spf13/cobra.(*Command).Execute\n\t/Users/jlewi/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992\nmain.main\n\t/Users/jlewi/git_hydros/cmd/main.go:157\nruntime.main\n\t/opt/homebrew/Cellar/go/1.22.1/libexec/src/runtime/proc.go:271\nruntime.goexit\n\t/opt/homebrew/Cellar/go/1.22.1/libexec/src/runtime/asm_arm64.s:1222"}
github.com/jlewi/hydros/pkg/app.(*App).ApplyPaths
    /Users/jlewi/git_hydros/pkg/app/app.go:158
github.com/jlewi/hydros/cmd/commands.NewApplyCmd.func1.1
    /Users/jlewi/git_hydros/cmd/commands/apply.go:55
github.com/jlewi/hydros/cmd/commands.NewApplyCmd.func1
    /Users/jlewi/git_hydros/cmd/commands/apply.go:56
github.com/spf13/cobra.(*Command).execute
    /Users/jlewi/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:944
github.com/spf13/cobra.(*Command).ExecuteC
    /Users/jlewi/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068
github.com/spf13/cobra.(*Command).Execute
    /Users/jlewi/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992
main.main
    /Users/jlewi/git_hydros/cmd/main.go:157
runtime.main
    /opt/homebrew/Cellar/go/1.22.1/libexec/src/runtime/proc.go:271
jlewi commented 4 months ago
ls -la
ls -la
total 0
drwxr-xr-x  10 jlewi  wheel  320 Apr 17 04:23 .
drwxr-xr-x   3 jlewi  wheel   96 Apr 12 17:10 ..
drwxr-xr-x   4 jlewi  wheel  128 Apr 17 04:23 .git
drwxr-xr-x   3 jlewi  wheel   96 Apr 12 17:10 .github
drwxr-xr-x   4 jlewi  wheel  128 Apr 17 04:23 app
drwxr-xr-x   7 jlewi  wheel  224 Apr 17 04:23 docs
drwxr-xr-x   4 jlewi  wheel  128 Apr 17 04:23 frontend
drwxr-xr-x   3 jlewi  wheel   96 Apr 17 04:23 iac
drwxr-xr-x   2 jlewi  wheel   64 Apr 17 04:23 images
drwxr-xr-x   4 jlewi  wheel  128 Apr 17 04:23 protos

So we see that directory

The git CLI also consisders it to be corrupt

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

So somehow the directory got corrupted.

At the very least we could try to recover by having hydros delete that directory but It would be good to understand why its getting corrupted.

jlewi commented 3 days ago

Here's the contents of a valid .git directory

-rw-r--r--    1 jlewi  staff   1128 Sep  2 15:17 COMMIT_EDITMSG
-rw-r--r--    1 jlewi  staff    595 Sep  2 14:51 FETCH_HEAD
-rw-r--r--    1 jlewi  staff     27 Sep  2 14:52 HEAD
-rw-r--r--    1 jlewi  staff     41 Aug 30 09:42 ORIG_HEAD
-rw-r--r--    1 jlewi  staff   4665 Sep  2 14:59 config
-rw-r--r--    1 jlewi  staff     73 Apr  9 16:41 description
drwxr-xr-x   15 jlewi  staff    480 Apr  9 16:41 hooks
-rw-r--r--    1 jlewi  staff  39612 Sep  2 15:37 index
drwxr-xr-x    3 jlewi  staff     96 Apr  9 16:41 info
drwxr-xr-x    4 jlewi  staff    128 Apr  9 16:41 logs
drwxr-xr-x  260 jlewi  staff   8320 Sep  2 15:17 objects
-rw-r--r--    1 jlewi  staff    233 Apr  9 16:41 packed-refs
drwxr-xr-x    6 jlewi  staff    192 Aug 25 17:24 refs

So lots of files and objects are missing

jlewi commented 3 days ago

My hypothesis is that those files might be automatically GC'd because they are in the temporary directory.

jlewi commented 3 days ago

It looks like the GoGit error occurs because when you try to open the repository it tries to read the file ${REPO}/.git/HEAD which doesn't exist in this case.