Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions scripts/cli/lec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand Down