Skip to content

Commit

Permalink
fix(changelog): create changelog file in the top level git directory …
Browse files Browse the repository at this point in the history
…instead of current directory

Closes: #2
  • Loading branch information
zbindenren committed Feb 4, 2021
1 parent d1eed18 commit ccfe76e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
9 changes: 9 additions & 0 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ func (c Command) Run() error {
return err
}

toplevelDir, err := gitCmd.TopLevelDir()
if err != nil {
return err
}

// resolv changelog file path
absChangelogPath := filepath.Join(toplevelDir, *c.file)
c.file = &absChangelogPath

gitCmd.Noop = c.noop

if err := c.validate(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func setup(t *testing.T, repoName string) (c Command, changelogPath string, clea
history: newBoolPtr(false),
noPrompt: newBoolPtr(true),
toStdOut: newBoolPtr(false),
file: newStrPtr(filepath.Join(tmp, repoName, dfltChangelogFile)),
file: newStrPtr(dfltChangelogFile),
version: newBoolPtr(false),
num: newIntPtr(0),
sinceTag: newStrPtr(""),
Expand Down
10 changes: 10 additions & 0 deletions internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ func (c Command) HasTags() (bool, error) {
return strings.TrimSpace(out) != "", nil
}

// TopLevelDir returns the git top level directory.
func (c Command) TopLevelDir() (string, error) {
topLevelDir, err := c.Run("rev-parse", "--show-toplevel")
if err != nil {
return "", err
}

return strings.TrimSpace(topLevelDir), nil
}

// CommitFor creates a Commit for a revision.
func (c Command) CommitFor(revision string) (*Commit, error) {
m, err := c.Run("show", "--format=%B", "-s", revision)
Expand Down

0 comments on commit ccfe76e

Please sign in to comment.