Skip to content

Commit 30b52c2

Browse files
authored
Merge pull request #1984 from GhostWriters/Updates
Add `ds --version <branch>` and adjust display of version text during `ds -u`
2 parents 7271eab + 662f6f4 commit 30b52c2

File tree

2 files changed

+57
-29
lines changed

2 files changed

+57
-29
lines changed

.scripts/update_self.sh

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

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

1212
local Title="Update ${APPLICATION_NAME}"
1313
local Question YesNotice NoNotice
@@ -16,17 +16,35 @@ update_self() {
1616
error "You need to specify a branch to update to."
1717
return 1
1818
fi
19-
Question="Would you like to update ${APPLICATION_NAME} to current branch ${CurrentBranch} now?"
19+
RemoteVersion="$(ds_version "${CurrentBranch}")"
20+
Question="Would you like to update ${APPLICATION_NAME} from ${CurrentVersion} to ${RemoteVersion} now?"
2021
NoNotice="${APPLICATION_NAME} will not be updated."
21-
YesNotice="Updating ${APPLICATION_NAME} to branch ${CurrentBranch}."
22+
YesNotice="Updating ${APPLICATION_NAME} from ${CurrentVersion} to ${RemoteVersion}."
2223
elif [[ ${BRANCH-} == "${CurrentBranch-}" ]]; then
23-
Question="Would you like to forcefully update ${APPLICATION_NAME} to current branch ${BRANCH} now?"
24-
NoNotice="${APPLICATION_NAME} will not be updated."
25-
YesNotice="Updating ${APPLICATION_NAME} to branch ${BRANCH}."
24+
RemoteVersion="$(ds_version "${CurrentBranch}")"
25+
if [[ ${CurrentVersion} == "${RemoteVersion}" ]]; then
26+
Question="Would you like to forcefully re-apply ${APPLICATION_NAME} update ${CurrentVersion}?"
27+
NoNotice="${APPLICATION_NAME} will not be updated."
28+
YesNotice="Updating ${APPLICATION_NAME} to ${RemoteVersion}."
29+
fi
2630
else
27-
Question="Would you like to update ${APPLICATION_NAME} from branch ${CurrentBranch} to ${BRANCH} now?"
28-
NoNotice="${APPLICATION_NAME} will not be updated from branch ${CurrentBranch} to ${BRANCH}."
29-
YesNotice="Updating ${APPLICATION_NAME} from branch ${CurrentBranch} to ${BRANCH}."
31+
RemoteVersion="$(ds_version "${BRANCH}")"
32+
Question="Would you like to update ${APPLICATION_NAME} from ${CurrentVersion} to ${RemoteVersion} now?"
33+
NoNotice="${APPLICATION_NAME} will not be updated from ${CurrentVersion} to ${RemoteVersion}."
34+
YesNotice="Updating ${APPLICATION_NAME} from ${CurrentVersion} to ${RemoteVersion}."
35+
fi
36+
popd &> /dev/null
37+
if [[ -z ${BRANCH-} && ${CurrentVersion} == "${RemoteVersion}" ]]; then
38+
if use_dialog_box; then
39+
{
40+
notice "${APPLICATION_NAME} is already up to date on branch ${BRANCH}."
41+
notice "Current version is ${CurrentVersion}"
42+
} |& dialog_pipe "${DC[TitleWarning]}${Title}" "${DC[CommandLine]} ds --update $*"
43+
else
44+
notice "${APPLICATION_NAME} is already up to date on branch ${CurrentBranch}."
45+
notice "Current version is ${CurrentVersion}"
46+
fi
47+
return
3048
fi
3149
if ! run_script 'question_prompt' Y "${Question}" "${Title}" "${FORCE:+Y}"; then
3250
if use_dialog_box; then
@@ -48,17 +66,8 @@ update_self() {
4866
commands_update_self() {
4967
local BRANCH=${1-}
5068
local Notice=${2-}
51-
local CurrentBranch
5269

5370
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 ! ds_update_available; then
57-
notice "${APPLICATION_NAME} is already up to date on branch ${BRANCH}."
58-
notice "Current version is $(ds_version)"
59-
return
60-
fi
61-
fi
6271
local QUIET=''
6372
if [[ -z ${VERBOSE-} ]]; then
6473
QUIET='--quiet'
@@ -93,7 +102,7 @@ commands_update_self() {
93102
git ls-tree -rt --name-only "${BRANCH}" | xargs sudo chown "${DETECTED_PUID}":"${DETECTED_PGID}" > /dev/null 2>&1 || true
94103
sudo chown -R "${DETECTED_PUID}":"${DETECTED_PGID}" "${SCRIPTPATH}/.git" > /dev/null 2>&1 || true
95104
sudo chown "${DETECTED_PUID}":"${DETECTED_PGID}" "${SCRIPTPATH}" > /dev/null 2>&1 || true
96-
notice "Updated to $(ds_version)"
105+
notice "Updated to [$(ds_version)]"
97106
popd &> /dev/null
98107
exec bash "${SCRIPTNAME}" -e
99108
}

main.sh

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,32 @@ run_script() {
118118
fi
119119
}
120120

121-
ds_version() {
122-
local Branch Version
121+
ds_branch() {
123122
pushd "${SCRIPTPATH}" &> /dev/null || fatal "Failed to change directory.\nFailing command: ${F[C]}pushd \"${SCRIPTPATH}\""
124123
git fetch --quiet &> /dev/null || true
124+
git branch --show
125+
popd &> /dev/null
126+
}
127+
128+
ds_version() {
129+
local CheckBranch=${1-}
130+
pushd "${SCRIPTPATH}" &> /dev/null || fatal "Failed to change directory.\nFailing command: ${F[C]}pushd \"${SCRIPTPATH}\""
131+
git fetch --all --quiet &> /dev/null || true
125132

126133
# Get the branch
127-
Branch="$(git symbolic-ref --short -q HEAD 2> /dev/null || true)"
134+
local commitish Branch
135+
if [[ -n ${CheckBranch-} ]]; then
136+
commitish="origin/${CheckBranch}"
137+
Branch="${CheckBranch}"
138+
else
139+
commitish='HEAD'
140+
Branch="$(ds_branch)"
141+
fi
128142
# Get the current tag. If no tag, use the commit instead.
129-
Version="$(git describe --tags --exact-match 2> /dev/null || true)"
143+
local Version
144+
Version="$(git describe --tags --exact-match "${commitish}" 2> /dev/null || true)"
130145
if [[ -z ${Version-} ]]; then
131-
Version="commit $(git rev-parse --short HEAD 2> /dev/null || true)"
146+
Version="commit $(git rev-parse --short "${commitish}" 2> /dev/null || true)"
132147
fi
133148

134149
echo "${Branch-} ${Version-}"
@@ -535,7 +550,11 @@ cmdline() {
535550
readonly VERBOSE=1
536551
;;
537552
V | version)
538-
readonly VERSION=1
553+
VERSION=''
554+
if [[ -n ${OPTARG-} && ${OPTARG:0:1} != '-' ]]; then
555+
VERSION="${OPTARG}"
556+
fi
557+
readonly VERSION
539558
;;
540559
x | debug)
541560
readonly DEBUG=1
@@ -844,7 +863,7 @@ main() {
844863
# Apply the GUI theme
845864
if ds_update_available; then
846865
notice "${APPLICATION_NAME} [${APPLICATION_VERSION}]"
847-
notice "An update to ${APPLICATION_NAME} is available. Run 'ds -u' to update."
866+
notice "An update to ${APPLICATION_NAME} is available. Run 'ds -u' to update to version $(ds_version "$(ds_branch)")."
848867
else
849868
info "${APPLICATION_NAME} [${APPLICATION_VERSION}]"
850869
fi
@@ -1205,8 +1224,8 @@ main() {
12051224
fi
12061225
exit
12071226
fi
1208-
if [[ -n ${VERSION-} ]]; then
1209-
echo "${APPLICATION_NAME} [${APPLICATION_VERSION}]"
1227+
if [[ -v VERSION ]]; then
1228+
echo "${APPLICATION_NAME} [$(ds_version "${VERSION}")]"
12101229
exit
12111230
fi
12121231
# Run Menus

0 commit comments

Comments
 (0)