-
Notifications
You must be signed in to change notification settings - Fork 0
fix: support init in bare repositories #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5455298
fb90b1a
7c22ae4
013e649
6dfe8bf
edd1ab2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,14 +27,31 @@ func (g *GitVolume) beforeInit(state *initState) error { | |
| if err != nil { | ||
| return fmt.Errorf("failed to get current directory: %w", err) | ||
| } | ||
| gitRoot, err := FindWorktreeRoot(cwd) | ||
| gitRoot, err := findInitRoot(cwd) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to find git repository root: %w", err) | ||
| } | ||
| state.configPath = filepath.Join(gitRoot, ConfigFileName) | ||
| return nil | ||
| } | ||
|
|
||
| // findInitRoot returns the directory where git-volume.yaml should be created. | ||
| // In a normal repository or worktree, that is the current worktree root. | ||
| // In a bare repository, that is the bare repository root itself. | ||
| func findInitRoot(startDir string) (string, error) { | ||
| worktreeRoot, err := FindWorktreeRoot(startDir) | ||
| if err == nil { | ||
| return worktreeRoot, nil | ||
| } | ||
|
|
||
| isBare, bareErr := isBareRepository(startDir) | ||
| if bareErr == nil && isBare { | ||
| return findCommonDir(startDir) | ||
| } | ||
|
|
||
| return "", err | ||
| } | ||
|
Comment on lines
+41
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current error handling logic discards the error from To improve error diagnostics, it would be better to return the error from the func findInitRoot(startDir string) (string, error) {
worktreeRoot, worktreeErr := FindWorktreeRoot(startDir)
if worktreeErr == nil {
return worktreeRoot, nil
}
isBare, bareErr := isBareRepository(startDir)
if bareErr != nil {
return "", fmt.Errorf("failed to check for bare repository: %w", bareErr)
}
if isBare {
return findCommonDir(startDir)
}
return "", worktreeErr
}References
|
||
|
|
||
| func (g *GitVolume) init(state *initState) error { | ||
| if err := os.MkdirAll(g.ctx.GlobalDir, DefaultDirPerm); err != nil { | ||
| return fmt.Errorf("failed to create global directory %s: %w", g.ctx.GlobalDir, err) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.