Skip to content

Commit 39d2d0d

Browse files
committed
fix: Fix forget command on implicitly managed files
1 parent 902809a commit 39d2d0d

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

internal/cmd/destroycmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (c *Config) runDestroyCmd(cmd *cobra.Command, args []string, sourceState *c
6363
var sourceAbsPath chezmoi.AbsPath
6464
sourceStateEntry := sourceState.MustEntry(targetRelPath)
6565
if sourceStateEntry.Origin().IsExternal() {
66-
c.errorf("warning: skipping external %s", targetRelPath)
66+
c.errorf("warning: skipping external %s\n", targetRelPath)
6767
continue
6868
}
6969
if _, ok := sourceStateEntry.(*chezmoi.SourceStateRemove); !ok {

internal/cmd/forgetcmd.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ func (c *Config) runForgetCmd(cmd *cobra.Command, args []string, sourceState *ch
3434
return err
3535
}
3636

37-
TARGET_REL_PATH:
3837
for _, targetRelPath := range targetRelPaths {
3938
sourceStateEntry := sourceState.MustEntry(targetRelPath)
4039

@@ -45,15 +44,21 @@ TARGET_REL_PATH:
4544
// OK, keep going.
4645
case chezmoi.SourceStateOriginRemove:
4746
c.errorf("warning: %s: cannot forget entry from remove\n", targetRelPath)
48-
continue TARGET_REL_PATH
47+
continue
4948
case *chezmoi.External:
5049
c.errorf("warning: %s: cannot forget entry from external %s\n", targetRelPath, sourceStateOrigin.OriginString())
51-
continue TARGET_REL_PATH
50+
continue
5251
default:
5352
panic(fmt.Sprintf("%s: %T: unknown source state origin type", targetRelPath, sourceStateOrigin))
5453
}
5554

56-
sourceAbsPath := c.SourceDirAbsPath.Join(sourceStateEntry.SourceRelPath().RelPath())
55+
relPath := sourceStateEntry.SourceRelPath().RelPath()
56+
if relPath.IsEmpty() {
57+
c.errorf("warning: %s: ignoring implicitly managed file\n", targetRelPath)
58+
continue
59+
}
60+
61+
sourceAbsPath := c.SourceDirAbsPath.Join(relPath)
5762
if !c.force {
5863
choice, err := c.promptChoice(fmt.Sprintf("Remove %s", sourceAbsPath), choicesYesNoAllQuit)
5964
if err != nil {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# test that chezmoi forget on a file in an exact_ directory does not delete the source directory
2+
exec chezmoi forget --debug --force $HOME${/}.dir${/}file2
3+
stderr 'warning: .dir/file2: ignoring implicitly managed file'
4+
exists $CHEZMOISOURCEDIR
5+
6+
-- home/user/.dir/file1 --
7+
# contents of .dir/file1
8+
-- home/user/.dir/file2 --
9+
# contents of .dir/file2
10+
-- home/user/.local/share/chezmoi/exact_dot_dir/file1 --
11+
# contents of .dir/file1

0 commit comments

Comments
 (0)