Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow source dir to be a git worktree #2911

Merged
merged 2 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/chezmoi/sourcestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (s *SourceState) Add(
newSourceStateEntriesByTargetRelPath := make(map[RelPath]SourceStateEntry)
nonEmptyDirs := make(map[SourceRelPath]struct{})
dirRenames := make(map[AbsPath]AbsPath)
DESTABSPATH:
DEST_ABS_PATH:
for _, destAbsPath := range destAbsPaths {
destAbsPathInfo := destAbsPathInfos[destAbsPath]
if !options.Filter.IncludeFileInfo(destAbsPathInfo) {
Expand Down Expand Up @@ -374,7 +374,7 @@ DESTABSPATH:
if options.PreAddFunc != nil {
switch err := options.PreAddFunc(targetRelPath); {
case errors.Is(err, Skip):
continue DESTABSPATH
continue DEST_ABS_PATH
case err != nil:
return err
}
Expand All @@ -398,7 +398,7 @@ DESTABSPATH:
if options.ReplaceFunc != nil {
switch err := options.ReplaceFunc(targetRelPath, newSourceStateEntry, oldSourceStateEntry); {
case errors.Is(err, Skip):
continue DESTABSPATH
continue DEST_ABS_PATH
case err != nil:
return err
}
Expand All @@ -413,7 +413,7 @@ DESTABSPATH:
oldSourceAbsPath := s.sourceDirAbsPath.Join(oldSourceEntryRelPath.RelPath())
newSourceAbsPath := s.sourceDirAbsPath.Join(sourceEntryRelPath.RelPath())
dirRenames[oldSourceAbsPath] = newSourceAbsPath
continue DESTABSPATH
continue DEST_ABS_PATH
}

// Otherwise, remove the old entry.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (

// Persistent state modes.
const (
persistentStateModeKey = "chezoi_persistent_state_mode"
persistentStateModeKey = "chezmoi_persistent_state_mode"

persistentStateModeEmpty persistentStateMode = "empty"
persistentStateModeReadOnly persistentStateMode = "read-only"
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/bitwardentemplatefuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type bitwardenConfig struct {
outputCache map[string][]byte
}

func (c *Config) bitwardenAttachmentTemplateFunc(name, itemid string) string {
output, err := c.bitwardenOutput([]string{"get", "attachment", name, "--itemid", itemid, "--raw"})
func (c *Config) bitwardenAttachmentTemplateFunc(name, itemID string) string {
output, err := c.bitwardenOutput([]string{"get", "attachment", name, "--itemid", itemID, "--raw"})
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,7 @@ func (c *Config) persistentPreRunRootE(cmd *cobra.Command, args []string) error
FOR:
for {
gitDirAbsPath := workingTreeAbsPath.JoinString(gogit.GitDirName)
if fileInfo, err := c.baseSystem.Stat(gitDirAbsPath); err == nil && fileInfo.IsDir() {
if _, err := c.baseSystem.Stat(gitDirAbsPath); err == nil {
c.WorkingTreeAbsPath = workingTreeAbsPath
break FOR
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/editcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (c *Config) runEditCmd(cmd *cobra.Command, args []string) error {
decryptedAbsPath chezmoi.AbsPath
}
var transparentlyDecryptedFiles []transparentlyDecryptedFile
TARGETRELPATH:
TARGET_REL_PATH:
for _, targetRelPath := range targetRelPaths {
sourceStateEntry := sourceState.MustEntry(targetRelPath)
sourceRelPath := sourceStateEntry.SourceRelPath()
Expand Down Expand Up @@ -154,7 +154,7 @@ TARGETRELPATH:
}
if err := c.baseSystem.Link(c.SourceDirAbsPath.Join(sourceRelPath.RelPath()), hardlinkAbsPath); err == nil {
editorArgs = append(editorArgs, hardlinkAbsPath.String())
continue TARGETRELPATH
continue TARGET_REL_PATH
}

// Otherwise, fall through to the default option of editing the
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/forgetcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (c *Config) runForgetCmd(cmd *cobra.Command, args []string, sourceState *ch
return err
}

TARGETRELPATH:
TARGET_REL_PATH:
for _, targetRelPath := range targetRelPaths {
sourceStateEntry := sourceState.MustEntry(targetRelPath)

Expand All @@ -46,10 +46,10 @@ TARGETRELPATH:
// OK, keep going.
case chezmoi.SourceStateOriginRemove:
c.errorf("warning: %s: cannot forget entry from remove\n", targetRelPath)
continue TARGETRELPATH
continue TARGET_REL_PATH
case *chezmoi.External:
c.errorf("warning: %s: cannot forget entry from external %s\n", targetRelPath, sourceStateOrigin.OriginString())
continue TARGETRELPATH
continue TARGET_REL_PATH
default:
panic(fmt.Sprintf("%s: %T: unknown source state origin type", targetRelPath, sourceStateOrigin))
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/cmd/initcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@ func (c *Config) runInitCmd(cmd *cobra.Command, args []string) error {

// If we're not in a working tree then init it or clone it.
gitDirAbsPath := c.WorkingTreeAbsPath.JoinString(git.GitDirName)
switch fileInfo, err := c.baseSystem.Stat(gitDirAbsPath); {
case err == nil && fileInfo.IsDir():
case err == nil && !fileInfo.IsDir():
return fmt.Errorf("%s: not a directory", gitDirAbsPath)
switch _, err := c.baseSystem.Stat(gitDirAbsPath); {
case errors.Is(err, fs.ErrNotExist):
workingTreeRawPath, err := c.baseSystem.RawPath(c.WorkingTreeAbsPath)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/readdcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *Config) runReAddCmd(cmd *cobra.Command, args []string, sourceState *che
})
sort.Sort(targetRelPaths)

TARGETRELPATH:
TARGET_REL_PATH:
for _, targetRelPath := range targetRelPaths {
sourceStateFile, ok := sourceStateEntries[targetRelPath].(*chezmoi.SourceStateFile)
if !ok {
Expand Down Expand Up @@ -118,7 +118,7 @@ TARGETRELPATH:
case choice == "yes":
break FOR
case choice == "no":
continue TARGETRELPATH
continue TARGET_REL_PATH
case choice == "all":
c.interactive = false
break FOR
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/testdata/scripts/issue2628.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cmp $HOME/.file golden/.file

chhome home2/user

# test that .chezmoignore.tmpl is read
# test that .chezmoiignore.tmpl is read
exec chezmoi apply
! exists $HOME/.file

Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ func pluralize(singular string) string {
return singular + "s"
}

// titleize returns s with its first rune titleized.
func titleize(s string) string {
// titleFirst returns s with its first rune converted to title case.
func titleFirst(s string) string {
if s == "" {
return s
}
Expand All @@ -128,7 +128,7 @@ func upperSnakeCaseToCamelCase(s string) string {
if i == 0 {
words[i] = strings.ToLower(word)
} else if !isWellKnownAbbreviation(word) {
words[i] = titleize(strings.ToLower(word))
words[i] = titleFirst(strings.ToLower(word))
}
}
return strings.Join(words, "")
Expand Down