Skip to content

Commit

Permalink
Fix panic when destination directory is /
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Jul 11, 2021
1 parent 0296e3c commit 0b499d7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/chezmoi/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ func (p AbsPath) String() string {

// TrimDirPrefix trims prefix from p.
func (p AbsPath) TrimDirPrefix(dirPrefixAbsPath AbsPath) (RelPath, error) {
if !strings.HasPrefix(string(p), string(dirPrefixAbsPath+"/")) {
dirAbsPath := dirPrefixAbsPath
if dirAbsPath != "/" {
dirAbsPath += "/"
}
if !strings.HasPrefix(string(p), string(dirAbsPath)) {
return "", &errNotInAbsDir{
pathAbsPath: p,
dirAbsPath: dirPrefixAbsPath,
}
}
return RelPath(p[len(dirPrefixAbsPath)+1:]), nil
return RelPath(p[len(dirAbsPath):]), nil
}

// Type implements github.com/spf13/pflag.Value.Type.
Expand Down

0 comments on commit 0b499d7

Please sign in to comment.