wip variable for .git

This commit is contained in:
monalisa 2023-08-07 14:04:56 +02:00
parent f7a76ff5d8
commit f2e5c8b41a
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
1 changed files with 5 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import (
)
const gitIgnoreFileName = ".gitignore"
const gitDirectoryName = ".git"
// Repository represents a Git repository or a directory
// that could later be initialized as Git repository.
@ -45,7 +46,7 @@ func (r *Repository) Root() string {
func (r *Repository) CurrentBranch() (string, error) {
// load .git/HEAD
ref, err := LoadReferenceFile(filepath.Join(r.rootPath, ".git", "HEAD"))
ref, err := LoadReferenceFile(filepath.Join(r.rootPath, gitDirectoryName, "HEAD"))
if err != nil {
return "", err
}
@ -62,7 +63,7 @@ func (r *Repository) CurrentBranch() (string, error) {
func (r *Repository) LatestCommit() (string, error) {
// load .git/HEAD
ref, err := LoadReferenceFile(filepath.Join(r.rootPath, ".git", "HEAD"))
ref, err := LoadReferenceFile(filepath.Join(r.rootPath, gitDirectoryName, "HEAD"))
if err != nil {
return "", err
}
@ -81,7 +82,7 @@ func (r *Repository) LatestCommit() (string, error) {
if err != nil {
return "", err
}
branchHeadRef, err := LoadReferenceFile(filepath.Join(r.rootPath, ".git", branchHeadPath))
branchHeadRef, err := LoadReferenceFile(filepath.Join(r.rootPath, gitDirectoryName, branchHeadPath))
if err != nil {
return "", err
}
@ -186,7 +187,7 @@ func NewRepository(path string) (*Repository, error) {
}
real := true
rootPath, err := folders.FindDirWithLeaf(path, ".git")
rootPath, err := folders.FindDirWithLeaf(path, gitDirectoryName)
if err != nil {
if !os.IsNotExist(err) {
return nil, err