git_tools

package
v0.0.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindGitRepoRootByTraversal

func FindGitRepoRootByTraversal(dir string) (string, error)

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

func FindGitRepoRootUsingGit(dir string) (string, error)

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

func IsAGitRepository(repoRoot string, levels int) (gitRoot, subDir string, err error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL