Skip to content

Commit a9af5f3

Browse files
committed
fix(build): improve repository reset logic and add version checkout support in build script
1 parent 168ce36 commit a9af5f3

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

scripts/build.sh

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,40 @@ clone_repo() {
376376

377377
# Check if rohas directory exists in current location
378378
if [[ -d "rohas" ]]; then
379-
log_verbose "Directory 'rohas' already exists. Using existing directory."
379+
log_verbose "Directory 'rohas' already exists. Resetting to remote..."
380380
cd rohas
381381
if [[ -d ".git" ]]; then
382+
# Determine the default branch
383+
local default_branch
384+
default_branch=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@' || echo "main")
385+
382386
if [[ "$VERBOSE" == "true" ]]; then
383-
log_info "Updating repository..."
384-
git pull || true
387+
log_info "Fetching from remote..."
388+
git fetch origin || true
389+
log_info "Resetting to origin/${default_branch}..."
390+
git reset --hard "origin/${default_branch}" || true
385391
else
386-
git pull >/dev/null 2>&1 || true
392+
git fetch origin >/dev/null 2>&1 || true
393+
git reset --hard "origin/${default_branch}" >/dev/null 2>&1 || true
394+
fi
395+
fi
396+
397+
if [[ -n "${ROHAS_VERSION}" ]]; then
398+
log_info "Checking out rohas version: ${ROHAS_VERSION}"
399+
if [[ "$VERBOSE" == "true" ]]; then
400+
git fetch --tags || true
401+
git checkout "${ROHAS_VERSION}" || git checkout "tags/${ROHAS_VERSION}" || {
402+
log_error "Failed to checkout version ${ROHAS_VERSION}"
403+
exit 1
404+
}
405+
else
406+
git fetch --tags >/dev/null 2>&1 || true
407+
git checkout "${ROHAS_VERSION}" >/dev/null 2>&1 \
408+
|| git checkout "tags/${ROHAS_VERSION}" >/dev/null 2>&1 \
409+
|| {
410+
log_error "Failed to checkout version ${ROHAS_VERSION}"
411+
exit 1
412+
}
387413
fi
388414
fi
389415
else

0 commit comments

Comments
 (0)