Skip to content

Commit

Permalink
ignore based on package dirent name prior to dot- adjustment
Browse files Browse the repository at this point in the history
If `--dotfiles` was enabled, files in the package such as
`dot-gitignore` would be translated to `.gitignore` and then ignored
by the default ignore list.  However any file named `dot-*` in a
package is obviously intended to be stowed as a dot file, so should
not be ignored.

To fix this, ignore based on the name in the package, not the
potentially translated name used for stowing.
  • Loading branch information
aspiers committed Sep 8, 2024
1 parent 2e0d39b commit 37025f5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
12 changes: 12 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ News file for Stow.
which reintroduced this warning when running Stow on Perl >= 5.40.0.
This has now been fixed.

*** =--dotfiles= option now works correctly with ignore lists

If the =--dotfiles= option was enabled, files in the package such
as =dot-gitignore= would be translated to =.gitignore= prior to
stowing, and consequently ignored by the default ignore list.
However any file named =dot-*= in a package is obviously intended
to be stowed as a dot file, so should not be ignored.

To fix this, Stow now ignores based on the name in the package,
not the potentially translated name used for stowing, and
similarly for unstowing.

*** Use shell-like parsing for =.stowrc= arguments

If a file path or regex in =.stowrc= has a space, the option
Expand Down
7 changes: 7 additions & 0 deletions doc/stow.texi
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,13 @@ option, Stow will create symlinks from @file{.bashrc} to
@file{stow/dot-emacs.d/init.el}. Any other files, whose name does not
begin with @samp{dot-}, will be processed as usual.

Note that when this option is enabled, any package file or directory
prefixed with @samp{dot-} is assumed to be named deliberately to be
stowed with a @samp{.} prefix, and therefore will only be ignored if
there is an entry in the ignore list (@xref{Ignore Lists}) which matches
this prefix. So for example, by default @file{dot-gitignore} would not
be ignored even though @samp{\.gitignore} is in the default ignore list.

@item --no-folding

This disables any further tree folding (@pxref{tree folding}) or
Expand Down
13 changes: 7 additions & 6 deletions lib/Stow.pm.in
Original file line number Diff line number Diff line change
Expand Up @@ -431,17 +431,17 @@ sub stow_contents {

my $package_node_path = join_paths($pkg_subdir, $node);
my $target_node = $node;
my $target_node_path = join_paths($target_subdir, $target_node);
next NODE if $self->ignore($stow_path, $package, $target_node_path);

if ($self->{dotfiles}) {
my $adjusted = adjust_dotfile($node);
if ($adjusted ne $node) {
debug(4, 1, "Adjusting: $node => $adjusted");
$target_node = $adjusted;
$target_node_path = join_paths($target_subdir, $target_node);
}
}
my $target_node_path = join_paths($target_subdir, $target_node);

next NODE if $self->ignore($stow_path, $package, $target_node_path);

$self->stow_node(
$stow_path,
Expand Down Expand Up @@ -800,6 +800,9 @@ sub unstow_contents {

my $package_node = $node;
my $target_node = $node;
my $target_node_path = join_paths($target_subdir, $target_node);

next NODE if $self->ignore($self->{stow_path}, $package, $target_node_path);

if ($self->{dotfiles}) {
if ($self->{compat}) {
Expand All @@ -819,13 +822,11 @@ sub unstow_contents {
if ($adjusted ne $node) {
debug(4, 1, "Adjusting: $node => $adjusted");
$target_node = $adjusted;
$target_node_path = join_paths($target_subdir, $target_node);
}
}
}
my $package_node_path = join_paths($pkg_subdir, $package_node);
my $target_node_path = join_paths($target_subdir, $target_node);

next NODE if $self->ignore($self->{stow_path}, $package, $target_node_path);

$self->unstow_node(
$package,
Expand Down
33 changes: 32 additions & 1 deletion t/dotfiles.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use strict;
use warnings;

use Test::More tests => 12;
use Test::More tests => 14;
use English qw(-no_match_vars);

use Stow::Util qw(adjust_dotfile unadjust_dotfile);
Expand Down Expand Up @@ -185,6 +185,21 @@ subtest("dot-. should not have that part expanded.", sub {
);
});

subtest("when stowing, dot-gitignore is not ignored by default", sub {
plan tests => 1;
$stow = new_Stow(dir => '../stow', dotfiles => 1);

make_file('../stow/dotfiles/dot-gitignore');

$stow->plan_stow('dotfiles');
$stow->process_tasks();
is(
readlink('.gitignore'),
'../stow/dotfiles/dot-gitignore',
=> "dot-gitignore shouldn't have been ignored"
);
});

subtest("unstow .bar from dot-bar", sub {
plan tests => 3;
$stow = new_Stow(dir => '../stow', dotfiles => 1);
Expand Down Expand Up @@ -233,3 +248,19 @@ subtest("unstow dot-emacs.d/init.el in --compat mode", sub {
ok(! -e '.emacs.d/init.el', '.emacs.d/init.el unstowed');
ok(-d '.emacs.d/' => '.emacs.d left behind');
});

subtest("when unstowing, dot-gitignore is not ignored by default", sub {
plan tests => 1;
$stow = new_Stow(dir => '../stow', dotfiles => 1);

system('pwd');
make_file('../stow/dotfiles/dot-gitignore');
-e '.gitignore' or make_link('.gitignore', '../stow/dotfiles/dot-gitignore');

$stow->plan_unstow('dotfiles');
$stow->process_tasks();
ok(
! -e ('.gitignore')
=> "dot-gitignore shouldn't have been ignored"
);
});

0 comments on commit 37025f5

Please sign in to comment.