Commit graph

40 commits

Author SHA1 Message Date
Adam Spiers 74f0182834 Add separate tests for .stowrc from $HOME and $PWD
.stowrc can be obtained from $HOME and/or the current working
directory; however only the $HOME case was tested before, because
during tests Stow was being run from $HOME.

So switch $TEST_DIR to an absolute path, create a new run_from/
subdirectory, and chdir to that before invoking any Stow code.  This
allows us to test the behaviour of .stowrc in $HOME and run_from/
separately.
2019-06-28 16:39:53 +01:00
Adam Spiers 5f875009f8
Avoid dereferencing $ENV{HOME} if it is undefined (#32)
Avoid dereferencing $ENV{HOME} if it is undefined
2019-06-28 00:41:55 +01:00
Adam Spiers 27796720d5 Upgrade to GPL v3 and add headers to files (#44)
Following advice from maintainers@gnu.org, bring Stow in line with
other GNU projects by upgrading it from GPL v2 to v3

  https://www.gnu.org/prep/maintain/html_node/Licensing-of-GNU-Packages.html#Licensing-of-GNU-Packages

as obtained in plain text and texinfo formats from

  https://www.gnu.org/licenses/

and adding appropriate headers:

  https://www.gnu.org/prep/maintain/html_node/License-Notices-for-Code.html#License-Notices-for-Code

Fixes #44: https://github.com/aspiers/stow/issues/44
2019-06-27 20:37:40 +01:00
Charles LeDoux dc42c34107 Add function to expand ~ in .stowrc files (#14)
Add a new expand_tilde() function that performs tilde expansion of
strings, and corresponding unit tests:

    * A ~ at the beginning of a path is expanded to the user's home
      directory.
    * Literal '~' can be provided with '\~'

Combine this with expand_environment() in a new expand_filepath()
function which applies all (both) required expansion functions to a
string, and use that in get_config_file_options() to expand .stowrc
options.

Add more tests to check that tilde expanded in correct places, i.e.:

    * expanded for --target and --dir
    * not expanded for --ignore, --defer, or --override

Update documentation on stowrc files according to this functionality
change.

Fixes #14: https://github.com/aspiers/stow/issues/14
2019-06-25 19:38:43 +01:00
Charles LeDoux 9674738792 Apply environment expansion to options in .stowrc files
Expand environment variables used in stowrc, as requested in

    https://savannah.gnu.org/bugs/?41826

This is achieved by creating a new function expand_environment() that
replaces any substring of the form '$VAR' or '${VAR}' with contents of
environment variable $VAR.  Literal '$' can be given by '\$'.

N.B. The function is only applied to the --target and --dir options,
and only for options specified in .stowrc; cli options are left
untouched.

Undefined variables are expanded to the empty string, as they would be
in normal shell parameter expansion.

Unit tests added accordingly:

  - Test expand_environment():
    * Expand $HOME
    * Expand ${HOME}
    * Expand ${WITH SPACE}
    * Expand '\$HOME'. Expected is '$HOME'
    * Expand ${UNDEFINED}. Expected is ''.

  - Test that it's applied to the correct options.

  - Test that CLI options are not expanded.
2019-06-25 19:38:26 +01:00
Charles LeDoux 4d1167ffd7 Parse cli and stowrc files separately
Why:

* We want to selectively apply expansion to:
    * Only options from stowrc files.
    * Only options that take a path.
* This requires ability to:
    * Differentiate cli options from stowrc options
    * Distinguish between individual stowrc options.

This change addresses the need by:

* Options from ARGV and stowrc files are separately parsed, resulting in
  two options hashes.
    * Creating an option hash from stowrc files allows modification of
      specific arguments without having to rely on something like regex
      parsing of the options.

* get_config_file_options modified to return options hash.
    * Uses the same parse_options function that parses ARGV

* Add Hash:Merge to dependencies in order to merge the two option
  hashes.

* process_options() merges the two option hashes.
    * Get option hash for ARGV
    * Get option hash from get_config_file_options().
    * Merge the two hashes with Hash::Merge.
    * Sanitation and checks are ran on the merged options.

* The options -S, -D, and -R are ignored in stowrc files.
    * Due to the way argument parsing happens, the effect of these
      actions is not carried from stowrc into parsing of cli options.
    * It doesn't seem to make sense to put these options in stowrc
      anyway.
2019-06-25 19:38:25 +01:00
Charles LeDoux feb885fda6 Factor out parsing of options
Why:

* Want to be able to selectively apply filepath expansion to:
    1. Only options in a stowrc file.
    2. Only options that take a file path.

* Because of need 1, any expansion must be performed on stowrc options
  before merging with cli options.

* Because of need 2, stowrc options need to be parsed before expansion
  in order to know which options need expanding.

This change addresses the need by:

* Create parse_options()
    * Implements option parsing logic previously in process_options()
    * Takes an array as parameter instead of assuming ARGV
* Edit process_options() to still work as expected.
    * Only change was to call parse_options() instead of directly
      parsing ARGV

* By factoring out the option parsing code, we can reuse the existing
  parsing code for stowrc options.
    * Allows expansion of only the option itself, i.e expansion on
      "$HOME/target" rather than "--target=$HOME/target"
    * Allows easy determination of which options need expansion.
2019-06-25 19:38:25 +01:00
Adam Spiers bb8b79e031 Don't warn when .stowrc is used
We fully support and expect some users using .stowrc, so there is
no reason to issue a warning when they do.
2019-06-25 19:38:25 +01:00
Adam Spiers 72ef83cebd Fix old descriptions of Stow (#22)
De-emphasise the package management aspects, since these days
almost everyone prefers to use modern package managers such as
rpm / dpkg / Nix for (system-wide) package management.

Also include more popular modern use cases for Stow such as management
of dotfiles and software compiled in the user's $HOME directory.

Fixes #22: https://github.com/aspiers/stow/issues/22
2019-06-25 16:52:33 +01:00
Adam Spiers e79c5938bc Return non-zero exit code when invalid option is specified (#34)
Also add a unit test for this.

Fixes #34: https://github.com/aspiers/stow/issues/34
2019-06-25 15:43:08 +01:00
Adam Spiers e618ef1526 remove duplicate "the" typo 2019-06-25 13:46:30 +01:00
Will Aoki b42cb89fdd Avoid dereferencing $ENV{HOME} if it is undefined 2019-04-03 09:49:53 -06:00
Adam Spiers 1a752bf70b make chkstow honour $STOW_DIR environment variable
Thanks to Matan Nassau for reporting this deficiency.
2019-02-09 17:03:45 +00:00
Adam Spiers 8d738353f8 fix documentation for --verbose
It actually goes up to 5 these days.  Thanks to Kristoffer Haugsbakk
for spotting that:

  http://lists.gnu.org/archive/html/bug-stow/2016-08/msg00000.html
2016-12-18 23:11:23 +00:00
Joris Vankerschaver 182acbbb64 Special processing for dotfiles 2016-10-04 17:51:01 +01:00
LE Manh Cuong 8544b2f0f5 Allow directory with trailing and leading spaces
- The `sanitize_path_options` functions remove all trailing
 and leading spaces. So any valid directory like ` 123`,
 `123 ` can not be used

 - Also if there are two directories ` 123` and `123`, and if
 user pick the ` 123` as option to `-d` or `-t`, then stow pick
 directory `123` as the argument instead of ` 123` as user want.

    ```
    STOW_DIR=. stow -n -v3 -t \ 123 456
    stow dir is /tmp/test
    stow dir path relative to target 123 is ..
    cwd now 123
    cwd restored to /tmp/test
    cwd now 123
    Planning stow of package 456...
    Stowing contents of ../456 (cwd=/tmp/test/123)
    Planning stow of package 456... done
    cwd restored to /tmp/test
    WARNING: in simulation mode so not modifying filesystem.
    ```
 - This commit remove the check in `sanitize_path_options` function,
 and now stow can work with those directories. There have been a check
 for valid directory, so we are safe.
2015-11-13 20:17:58 +07:00
Adam Spiers a111eeb8ae Do more validation on --dir / --target directories (#7)
Previously STOW_DIR=0 would cause the cwd to be used as the STOW_DIR.
Make that instead raise an error.  Do similar validation on the target
directory.

Closes #7 - https://github.com/aspiers/stow/pull/7
2015-11-11 12:30:50 +00:00
Adam Spiers d0f3e5458f Correctly handle empty STOW_DIR (#5, #6)
In shell, a variable is often considered unset even if it is
set to the empty string.  In other words,

  STOW_DIR= stow [args]

is an idiomatic alternative to writing:

  unset STOW_DIR
  stow [args]

and it also has the advantage of temporarily "unsetting" STOW_DIR
for a single command.

Therefore we should treat STOW_DIR being set to the empty string
as equivalent to it not being set at all.

Thanks to Cuong Manh Le for highlighting this issue!

Fixes #6  - https://github.com/aspiers/stow/issues/6
Closes #5 - https://github.com/aspiers/stow/pull/5
2015-11-11 11:28:47 +00:00
Adam Spiers 67936bd7de Fix RT ticket #75349
https://rt.cpan.org/Ticket/Display.html?id=75349
2012-07-09 01:05:27 +01:00
Adam Spiers db7819dbf2 Bug #36478 - fix Perl warnings from 'require 5.6.1;'
https://savannah.gnu.org/bugs/?36478
2012-05-16 11:02:40 +01:00
Adam Spiers ed12c787df Add --no-folding option. 2012-02-18 20:33:34 +00:00
Adam Spiers 17d3586e84 Remove -a option for safety reasons (but keep --adopt). 2012-02-18 20:33:34 +00:00
Adam Spiers 2c5950ed00 Add --adopt to usage text. 2012-02-18 17:14:50 +00:00
Adam Spiers 7b36267dd2 Improve ordering of options in usage text. 2012-02-18 17:14:50 +00:00
Adam Spiers 9c6faebb95 Include --simulate in usage text. 2012-02-18 11:53:46 +00:00
Adam Spiers 25b9ce0f21 Remove reference to old FSF address (thank you rpmlint for catching this!) 2012-01-12 17:54:32 +00:00
Adam Spiers 7e44666640 Add --adopt / -a option. 2012-01-09 21:29:34 +00:00
Adam Spiers d3847e951a Make stow script return true for t/stow.t
According to http://matrix.cpantesters.org/?dist=Stow
this only seems to be an issue with Perl <= 5.8.7.
2011-12-11 13:23:37 +00:00
Adam Spiers 195c80e9d7 Significantly improve the handling of --with-pmdir. 2011-12-07 20:48:50 +00:00
Adam Spiers 8817815059 Make capitalisation consistent in usage text. 2011-12-07 20:31:20 +00:00
Adam Spiers bc661ae77b Add bug-reporting email address and a couple of URLs to usage text
to comply with GNU Coding Standards for --help option.
2011-12-06 16:26:29 +00:00
Adam Spiers 4d6c23600b Fix corner case where only -d is specified as a single directory. 2011-12-01 16:23:04 +00:00
Adam Spiers 1f41616b12 Tidy up chkstow code and documentation. 2011-11-26 16:34:57 +00:00
Adam Spiers bcac91d68a Remove quote stripping code.
I'm guessing it was added due to a misunderstanding of how shell
quoting works.  When you invoke

   stow --ignore=".#.*" ...

the shell strips out the quotes before the Perl process ever sees them.
I can't imagine any sensible scenario in which you would need to invoke

   stow --ignore='"foo"'

but if the user has a filename containing quotes at the beginning and
end, they can now choose to ignore it (prior to this patch, they couldn't).
2011-11-26 16:34:57 +00:00
Adam Spiers 3d414dc071 Improve conflict reporting 2011-11-26 16:34:57 +00:00
Adam Spiers 55d3f05cf2 Ditch obsolete --conflicts option and update misleading documentation. 2011-11-26 16:34:57 +00:00
Adam Spiers 0db112441f Strip superfluous quotes from $hash{'lookups'} 2011-11-26 16:34:54 +00:00
Adam Spiers a7262a98bc Avoid use of map in void context 2011-11-26 15:10:28 +00:00
Adam Spiers a84ba4c16d Convert man page to POD format which is easier to maintain within stow.in. 2011-11-26 15:10:27 +00:00
Adam Spiers 58625800ee Reorganise more files into subdirectories and add CPAN support via Module::Build 2011-11-26 15:10:26 +00:00