Skip to content

fix: support init in bare repositories#31

Merged
laggu merged 6 commits intodevelopfrom
gv-032
Mar 15, 2026
Merged

fix: support init in bare repositories#31
laggu merged 6 commits intodevelopfrom
gv-032

Conversation

@laggu
Copy link
Owner

@laggu laggu commented Mar 14, 2026

Summary

  • allow git volume init to fall back to the bare repo root when no worktree root exists
  • keep existing behavior for regular repos/worktrees
  • add a regression test covering init from a bare repository

Testing

  • GOCACHE=/tmp/gocache go test ./internal/gitvolume/...
  • GOCACHE=/tmp/gocache go test ./...
  • manual repro in a temporary bare repo with git-volume init

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the git volume init command to support bare Git repositories. Previously, initialization might fail in such environments due to the absence of a worktree. The changes introduce a more robust mechanism to locate the correct repository root for configuration file placement, ensuring consistent behavior across different Git repository types. This improves the utility of the git-volume tool for a wider range of Git workflows.

Highlights

  • Bare Repository Support: The git volume init command now correctly initializes git-volume.yaml within bare Git repositories, falling back to the bare repo root when no worktree root is present.
  • Initialization Logic Refinement: A new findInitRoot function was introduced to intelligently determine the appropriate directory for git-volume.yaml, prioritizing worktree roots and then bare repository roots.
  • Regression Test Added: A new test case, TestInit_BareRepository, was added to ensure the init command functions as expected in bare Git repository environments.
Changelog
  • internal/gitvolume/init.go
    • Introduced findInitRoot function to determine the correct initialization directory, supporting both worktrees and bare repositories.
    • Updated beforeInit to use the new findInitRoot logic for repository root detection.
  • internal/gitvolume/init_test.go
    • Added a new test case TestInit_BareRepository to verify git volume init functionality in bare Git repositories.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for running git volume init inside a bare git repository. The implementation correctly falls back from checking for a worktree to checking for a bare repository root. A comprehensive regression test is included to verify the new functionality. My review includes one suggestion on internal/gitvolume/init.go to improve the error message when a git repository cannot be found, making it clearer for the user and simplifying the error handling logic.

@laggu
Copy link
Owner Author

laggu commented Mar 15, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly adds support for git volume init in bare repositories, which is a good enhancement. The logic to fall back to the bare repo root when a worktree isn't found is sound, and the addition of a regression test is great. The refactoring in other tests to use t.Cleanup is also a welcome improvement for consistency and robustness. I've found one minor area for improvement in the new test to better align with the project's style guide and the other changes in this PR.

@laggu
Copy link
Owner Author

laggu commented Mar 15, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly adds support for running git volume init in bare repositories. The new logic in findInitRoot properly falls back to finding the bare repo root. The addition of TestInit_BareRepository is excellent for ensuring this functionality is maintained.

The updates across the test suite to use t.Cleanup and require.NoError also improve the robustness and clarity of the tests.

I have one suggestion in internal/gitvolume/init.go to simplify the implementation of the new findInitRoot function for better readability.

@laggu
Copy link
Owner Author

laggu commented Mar 15, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for git volume init in bare repositories, which is a great enhancement. The implementation introduces a fallback mechanism to find the repository root. The associated test changes to use t.Cleanup and check for errors are also solid improvements. I've found one potential issue with the fallback logic that could lead to incorrect behavior in edge cases involving worktrees and have provided a suggestion to make it more robust. Otherwise, the changes look good.

@laggu
Copy link
Owner Author

laggu commented Mar 15, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request successfully adds support for running git volume init within bare repositories by introducing fallback logic to identify the repository root. A corresponding regression test has been added to verify this new functionality. The pull request also includes several valuable refactorings in the test suite, replacing defer with t.Cleanup for more robust resource management and error checking. I've identified one medium-severity issue in the error handling of the new findInitRoot function, where an error could be silently discarded, potentially leading to confusing error messages. A suggestion to improve the error handling logic is provided.

Comment on lines +41 to +53
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
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current error handling logic discards the error from isBareRepository (bareErr) if it fails, and instead returns the initial error from FindWorktreeRoot (err). This could be misleading for the user. For example, if checking for a bare repository fails due to a permissions issue, the user will see a generic "not a git worktree" error instead of the more specific permissions error.

To improve error diagnostics, it would be better to return the error from the isBareRepository check if it fails. This would help the user understand the root cause of the failure more easily when they are running init in what they believe is a bare repository.

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
  1. The style guide recommends wrapping errors to add context using fmt.Errorf("...: %w", err). The suggested change improves error handling by capturing and wrapping a previously discarded error, providing more specific context to the user upon failure. (link)

@laggu laggu merged commit 44724e3 into develop Mar 15, 2026
6 checks passed
@laggu laggu deleted the gv-032 branch March 15, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant