Skip to content

Commit

Permalink
Merge pull request #34 from yobeonline/open_with_options
Browse files Browse the repository at this point in the history
Switching git.PlainOpen for git.PlainOpenWithOptions so that git-semver can be called from a subdirectory
  • Loading branch information
mdomke authored Feb 12, 2024
2 parents c72e6ac + 0bcf686 commit c36a67b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [6.8.1] - ?
### Fixed
* An error was issued when invoked from subfolder of the repository whereas `git-describe` ususally succeeds in such cases.

## [6.8.0] - 2023-09-22
### Added
* New flag `-match` that can be used to select only specific tags matching a glob pattern into the
Expand Down
3 changes: 2 additions & 1 deletion version/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func GitDescribe(path string, opts ...Option) (*RepoHead, error) {
apply(&options)
}

repo, err := git.PlainOpen(path)
openOpts := git.PlainOpenOptions{DetectDotGit: true}

Check failure on line 53 in version/git.go

View workflow job for this annotation

GitHub Actions / lint

undefined: git (typecheck)
repo, err := git.PlainOpenWithOptions(path, &openOpts)

Check failure on line 54 in version/git.go

View workflow job for this annotation

GitHub Actions / lint

undefined: git (typecheck)
if err != nil {
return nil, fmt.Errorf("failed to open repo: %w", err)
}
Expand Down
10 changes: 10 additions & 0 deletions version/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ func TestGitDescribe(t *testing.T) {
Hash: commit2.String(),
CommitsSinceTag: 0,
})

dir += "/subfoler"
err = os.Mkdir(dir, 0750)
assert.NoError(err)

test(&RepoHead{
LastTag: tag3.Name().Short(),
Hash: commit2.String(),
CommitsSinceTag: 0,
})
}

func TestGitDescribeError(t *testing.T) {
Expand Down

0 comments on commit c36a67b

Please sign in to comment.