diff --git a/scripts/cli/lec.sh b/scripts/cli/lec.sh index f8a29cd..4aa03ac 100755 --- a/scripts/cli/lec.sh +++ b/scripts/cli/lec.sh @@ -367,18 +367,16 @@ _getWorktreeDir() { _removeWorktree() { local worktree="${1:?Worktree directory required}" - if [[ ! -d "${worktree}" ]]; then - _errorExit "${worktree} is not a directory" - fi - local worktree_name="${worktree##*/}" - _print_step "Shutting down project and removing Docker volumes..." - ( - cd "${worktree}" || exit 1 + if [[ -d "${worktree}" ]]; then + _print_step "Shutting down project and removing Docker volumes..." + ( + cd "${worktree}" || exit 1 - ./gradlew stop -Plr.docker.environment.clear.volume.data=true - ) + ./gradlew stop -Plr.docker.environment.clear.volume.data=true + ) + fi _print_step "Removing project dir..." _git worktree remove --force "${worktree_name}" @@ -638,17 +636,24 @@ cmd_init() { worktree_name="lec-${ticket}" - existing_worktree="$(_getWorktreeDir "${worktree_name}")" - if [[ "${existing_worktree}" ]]; then - _errorExit "Worktree ${worktree_name} already exists at: ${existing_worktree}" - fi - if [[ -z "${liferay_version}" ]]; then liferay_version="$(_selectLiferayRelease)" fi _cancelIfEmpty "${liferay_version}" _verifyLiferayVersion "${liferay_version}" + existing_worktree="$(_getWorktreeDir "${worktree_name}")" + + if [[ "${existing_worktree}" ]]; then + _print_step "Worktree ${worktree_name} already exists at: ${existing_worktree}. You may remove it if you want to create a worktree with the same name." + + if ! _confirm "Are you sure you want to remove the project ${C_YELLOW}${worktree_name}${C_NC}? The project directory and all data will be removed."; then + exit 1 + fi + + _removeWorktree "${existing_worktree}" + fi + if _git rev-parse --verify --quiet "refs/heads/${worktree_name}" >/dev/null; then _print_step "Deleting stale branch ${worktree_name}" if ! _git branch -D "${worktree_name}"; then