diff --git a/bash_tools/bin/stowsh b/bash_tools/bin/stowsh index d0437f7..a6fada9 100755 --- a/bash_tools/bin/stowsh +++ b/bash_tools/bin/stowsh @@ -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: ### @@ -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 } diff --git a/docker/test/contrib/opt/app/tests/test_install/test.bats b/docker/test/contrib/opt/app/tests/test_install/test.bats index f034e7c..593c71a 100644 --- a/docker/test/contrib/opt/app/tests/test_install/test.bats +++ b/docker/test/contrib/opt/app/tests/test_install/test.bats @@ -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}" ]] +}