Permalink
Browse files

support $DFM_REPO outside of $HOME

  • Loading branch information...
1 parent b6898dc commit 46ae22df29d45ece31c7bc9255d27f1ce08311a6 @justone committed Oct 17, 2012
Showing with 44 additions and 8 deletions.
  1. +1 −0 CHANGELOG.md
  2. +19 −8 dfm
  3. +24 −0 t/01.simple.t
View
@@ -1,5 +1,6 @@
# v0.7 (unreleased)
+* dotfiles repository can now be outside of home directory, using $DFM_REPO
* add help subcommand and refactor help handling
* make 'help' the default subcommand (seth--)
* better parsing of arguments to preserve all arguments passed through to git subcommands
View
27 dfm
@@ -63,7 +63,7 @@ my $commands = {
DEBUG("Running in [$RealBin] and installing in [$home]");
# uninstall files
- uninstall_files( $home . '/' . $repo_dir, $home );
+ uninstall_files( _abs_repo_path( $home, $repo_dir ), $home );
# remove the bash loader
unconfigure_bash_loader();
@@ -74,7 +74,7 @@ my $commands = {
GetOptionsFromArray( $argv, \%opts, 'message=s', 'no-commit|n' );
# import files
- import_files( $home . '/' . $repo_dir, $home, $argv );
+ import_files( _abs_repo_path( $home, $repo_dir ), $home, $argv );
},
'help' => sub {
my $argv = shift;
@@ -254,7 +254,7 @@ sub DEBUG {
sub fetch_updates {
my $opts = shift;
- chdir( $home . '/' . $repo_dir );
+ chdir( _abs_repo_path( $home, $repo_dir ) );
if ( !$opts->{'no-fetch'} ) {
DEBUG('fetching changes');
@@ -270,7 +270,7 @@ sub fetch_updates {
sub merge_and_install {
my $opts = shift;
- chdir( $home . '/' . $repo_dir );
+ chdir( _abs_repo_path( $home, $repo_dir ) );
my $current_branch = get_current_branch();
check_remote_branch($current_branch);
@@ -314,7 +314,7 @@ sub install {
DEBUG("Running in [$RealBin] and installing in [$home]");
- install_files( $home . '/' . $repo_dir, $home );
+ install_files( _abs_repo_path( $home, $repo_dir ), $home );
# link in the bash loader
if ( -e "$home/$repo_dir/.bashrc.load" ) {
@@ -401,7 +401,7 @@ sub install_files {
$recurse_options = {
install_only => [
map { s/^$recurse\///; $_ }
- grep {/^$recurse/} @$install_only
+ grep {/^$recurse/} @$install_only
]
};
}
@@ -621,7 +621,7 @@ sub import_files {
}
}
- install_files( $home . '/' . $repo_dir,
+ install_files( _abs_repo_path( $home, $repo_dir ),
$home, { install_only => [@$files] } );
INFO( "Committing with message '$message'"
@@ -708,12 +708,23 @@ sub _run_git {
my $cwd_before_git = getcwd();
DEBUG( 'running git ' . join( ' ', @args ) . " in $home/$repo_dir" );
- chdir( $home . '/' . $repo_dir );
+ chdir( _abs_repo_path( $home, $repo_dir ) );
system( 'git', @args );
chdir($cwd_before_git);
}
+sub _abs_repo_path {
+ my ( $home, $repo ) = @_;
+
+ if ( File::Spec->file_name_is_absolute($repo) ) {
+ return $repo;
+ }
+ else {
+ return $home . '/' . $repo;
+ }
+}
+
# when symlinking from source_dir into target_dir, figure out if there's a
# relative path between the two
sub _calculate_symlink_base {
View
@@ -321,6 +321,30 @@ subtest 'repo dir env override' => sub {
ok( !-e "$home/t", 'no t dir in homedir' );
};
+subtest 'repo dir env override not in home' => sub {
+ focus('repo_dir_override_not_in_home');
+
+ my ( $home, $repo, $origin );
+ ( $home, $repo, $origin ) = minimum_home('first');
+
+ diag("$repo");
+ `rm -rf $Bin/rep`;
+ `mv $repo $Bin/rep`;
+ local $ENV{'DFM_REPO'} = "$Bin/rep";
+
+ # simulate running dfm from the homedir instead of inside the repo
+ run_dfm( $home, $home, 'install', '--verbose' );
+
+ ok( -d "$home/.backup", 'main backup dir exists' );
+ ok( -l "$home/bin", 'bin is a symlink' );
+ ok( !-e "$home/.git", ".git does not exist in \$home" );
+ ok( !-e "$home/.gitignore", '.gitignore does not exist' );
+ ok( !-e "$home/.dfminstall", '.dfminstall does not exist' );
+ is( readlink("$home/bin"), '../rep/bin', 'bin points into repo' );
+ ok( !-e "$home/README.md", 'no README.md in homedir' );
+ ok( !-e "$home/t", 'no t dir in homedir' );
+};
+
subtest 'command first' => sub {
focus('command_first');

0 comments on commit 46ae22d

Please sign in to comment.