Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindGitRepoRootByTraversal ¶
FindGitRepoRootByTraversal finds the Git repository root for the given directory by manually checking for a .git directory.
Parameters:
- dir: The directory to start the search from.
Returns:
- string: The absolute path to the root of the Git repository.
- error: An error if the Git repository root could not be found.
Example:
root, err := FindGitRepoRootByTraversal("/path/to/start") if err != nil { log.Fatalf("Error finding Git repo root: %v", err) } fmt.Printf("Git repository root: %s\n", root)
func FindGitRepoRootUsingGit ¶
FindGitRepoRootUsingGit finds the root of a Git repository using the `git` command.
Parameters:
- dir: The directory to start the search from.
Returns:
- string: The absolute path to the root of the Git repository.
- error: An error if the Git repository root could not be found.
Example:
root, err := FindGitRepoRootUsingGit("/path/to/start") if err != nil { log.Fatalf("Error finding Git repo root: %v", err) } fmt.Printf("Git repository root: %s\n", root)
func IsAGitRepository ¶
IsAGitRepository checks if the given directory or any of its parent directories up to `levels` is a Git repository. It returns the git root directory, the subdirectory passed relative to the git root, and any error encountered.
Parameters:
- repoRoot: The directory to start the search from.
- levels: The number of parent directories to check upwards.
Returns:
- gitRoot: The absolute path to the root of the Git repository.
- subDir: The relative path from the Git root to the original directory.
- err: An error if the Git repository root could not be found or if any other error occurred.
Example:
gitRoot, subDir, err := IsAGitRepository("/path/to/start", 5) if err != nil { log.Fatalf("Error finding Git repository: %v", err) } fmt.Printf("Git repository root: %s, Subdirectory: %s\n", gitRoot, subDir)
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.