Skip to content

Commit 4ec91cf

Browse files
committed
Make ds -u skip updating if no update is needed.
1 parent 6ef0a28 commit 4ec91cf

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

.scripts/update_self.sh

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@ set -Eeuo pipefail
33
IFS=$'\n\t'
44

55
update_self() {
6-
cd "${SCRIPTPATH}" || fatal "Failed to change directory.\nFailing command: ${F[C]}cd \"${SCRIPTPATH}\""
76
local BRANCH CurrentBranch
8-
BRANCH=${1-$(git branch --show)}
7+
BRANCH=${1-}
8+
pushd "${SCRIPTPATH}" &> /dev/null || fatal "Failed to change directory.\nFailing command: ${F[C]}push \"${SCRIPTPATH}\""
99
CurrentBranch="$(git branch --show)"
10+
popd &> /dev/null
1011

1112
local Title="Update DockSTARTer"
1213
local Question YesNotice NoNotice
1314
if [[ -z ${BRANCH-} ]]; then
14-
error "You need to specify a branch to update to."
15-
return 1
16-
fi
17-
if [[ ${BRANCH-} == "${CurrentBranch-}" ]]; then
15+
if [[ -z ${CurrentBranch-} ]]; then
16+
error "You need to specify a branch to update to."
17+
return 1
18+
fi
19+
Question="Would you like to update DockSTARTer to branch ${CurrentBranch} now?"
20+
NoNotice="DockSTARTer will not be updated."
21+
YesNotice="Updating DockSTARTer to branch ${CurrentBranch}."
22+
elif [[ ${BRANCH-} == "${CurrentBranch-}" ]]; then
1823
Question="Would you like to update DockSTARTer to branch ${BRANCH} now?"
1924
NoNotice="DockSTARTer will not be updated."
2025
YesNotice="Updating DockSTARTer to branch ${BRANCH}."
@@ -43,7 +48,16 @@ update_self() {
4348
commands_update_self() {
4449
local BRANCH=${1-}
4550
local Notice=${2-}
51+
local CurrentBranch
4652

53+
pushd "${SCRIPTPATH}" &> /dev/null || fatal "Failed to change directory.\nFailing command: ${F[C]}push \"${SCRIPTPATH}\""
54+
if [[ -z ${BRANCH-} ]]; then
55+
BRANCH="$(git branch --show)"
56+
if ! run_script 'ds_update_available'; then
57+
notice "DockSTARTer is already up to date on branch ${BRANCH}."
58+
return
59+
fi
60+
fi
4761
local QUIET=''
4862
if [[ -z ${VERBOSE-} ]]; then
4963
QUIET='--quiet'
@@ -78,6 +92,7 @@ commands_update_self() {
7892
git ls-tree -rt --name-only "${BRANCH}" | xargs sudo chown "${DETECTED_PUID}":"${DETECTED_PGID}" > /dev/null 2>&1 || true
7993
sudo chown -R "${DETECTED_PUID}":"${DETECTED_PGID}" "${SCRIPTPATH}/.git" > /dev/null 2>&1 || true
8094
sudo chown "${DETECTED_PUID}":"${DETECTED_PGID}" "${SCRIPTPATH}" > /dev/null 2>&1 || true
95+
popd &> /dev/null
8196
exec bash "${SCRIPTNAME}" -e
8297
}
8398

0 commit comments

Comments
 (0)