Skip to content

Commit

Permalink
Merge pull request #13 from cjvirtucio87/issue-1
Browse files Browse the repository at this point in the history
issue#1: skipping pre-existing files or directories at DEST_DIR
  • Loading branch information
cjvirtucio87 authored Mar 6, 2023
2 parents 42e4f4b + 5217da6 commit bcd45f3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
8 changes: 7 additions & 1 deletion bash_tools/bin/stowsh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ shopt -s dotglob
### symlinks to them on your DEST_DIR
### arguments:
### dotfiles_url: URL for your dotfiles
### path: path in your dotfiles repo to your actual dotfiles
### subpath: path in your dotfiles repo to your actual dotfiles
###
### Examples:
###
Expand Down Expand Up @@ -119,6 +119,12 @@ function _install {
local dest_filepath
dest_filepath="${DEST_DIR}/$(basename "${filename}")"
_log 'install' "creating link: [${dest_filepath}]"

if [[ -f "${dest_filepath}" ]] || [[ -d "${dest_filepath}" ]]; then
_log 'install' "[${dest_filepath} already exists and is not a symlink; skipping"
continue
fi

ln -s "${filename}" "${dest_filepath}"
done
}
Expand Down
26 changes: 26 additions & 0 deletions docker/test/contrib/opt/app/tests/test_install/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,29 @@ function test_install_installs_dotfiles_with_folders_subpath { # @test
_init_managed_dir
_test_install "${path}"
}

function _test_install_skips_files_or_directories_already_present { # @test
init_dotfiles 'simple'
_init_managed_dir
_test_install
_diff_repo_dest_dir

local expected_filename='.new_file'
local dest_expected_filepath="${DEST_DIR}/${expected_filename}"
echo -n 'hello' > "${dest_expected_filepath}"

stowsh add "${dest_expected_filepath}"
stowsh git add -A
stowsh git commit -m 'initial file'

local second_expected_filename='.second_new_file'
local dest_second_expected_filepath="${DEST_DIR}/${second_expected_filename}"
echo -n 'hello' > "${dest_second_expected_filepath}"

stowsh install "${DOTFILES_URL}"

[[ -f "${dest_second_expected_filepath}" ]]

! diff --unified "${dest_expected_dirpath}/" "${MANAGED_DIR}/${actual_dir}"
! [[ -L "${dest_second_expected_filepath}" ]]
}

0 comments on commit bcd45f3

Please sign in to comment.