Skip to content

Commit a7033b6

Browse files
committed
git update-git-for-windows: optionally update from a fork
For the upcoming ARM64 support, as well as for the Microsoft fork of Git for Windows, it would be helpful if there was a way to update from the GitHub Releases of the respective fork instead of Git for Windows' own fork. To facilitate that, let's introduce support for a `git-update-git-for-windows.config` file next to the script: if it exists, treat it as a Git config file and read the `update.fromFork` value, and then continue with that value inserted into the URL https://github.com/<fork>/releases. Example: to ask the updater to look for new versions at https://github.com/dennisameling/git/releases, run the following command as administrator: git config \ -f "$(git --exec-path)/git-update-git-for-windows.config" \ update.fromFork dennisameling/git This also overrides the label "Git for Windows" with "Git"; The `update.gitLabel` setting in the same `.config` file can be used to over-override this. If the `.config` file does not contain any `update.fromFork`, the file is ignored altogether. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent f95524e commit a7033b6

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

git-extra/git-update-git-for-windows

+23-5
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,26 @@ update_git_for_windows () {
174174
;;
175175
esac
176176

177-
latest_tag_url=https://gitforwindows.org/latest-tag.txt
177+
test -f "$0.config" &&
178+
fork="$(git config -f "$0.config" update.fromFork)" &&
179+
test -n "$fork" ||
180+
fork=
181+
182+
if test -n "$fork"
183+
then
184+
git_label="$(git config -f "$0.config" update.gitLabel)"
185+
test -n "$git_label" || git_label=Git
186+
187+
releases_url=https://api.github.com/repos/$fork/releases
188+
latest_tag_url=$releases_url/latest
189+
latest_eval='latest=${latest_tag#*\"tag_name\": \"}; latest=${latest%%\"*}'
190+
else
191+
git_label="Git for Windows"
192+
releases_url=https://api.github.com/repos/git-for-windows/git/releases
193+
latest_tag_url=https://gitforwindows.org/latest-tag.txt
194+
latest_eval='latest=${latest_tag#v}'
195+
fi
196+
178197
latest_tag=$(http_get $latest_tag_url) ||
179198
case $?,"$proxy" in
180199
7,)
@@ -190,13 +209,13 @@ update_git_for_windows () {
190209
;;
191210
esac
192211

193-
latest=${latest_tag#v}
212+
eval "$latest_eval"
194213
# Did we ask about this version already?
195214
recently_seen="$(get_recently_seen)"
196215
test -n "$quiet" && test "x$recently_seen" = "x$latest" && return
197216

198217
version=$(git --version | sed "s/git version //")
199-
echo "Git for Windows $version (${bit}bit)" >&2
218+
echo "$git_label $version (${bit}bit)" >&2
200219
if test -z "$testing" && test "$latest" = "$version"
201220
then
202221
echo "Up to date" >&2
@@ -215,7 +234,6 @@ update_git_for_windows () {
215234
esac
216235

217236
echo "Update $latest is available" >&2
218-
releases_url=https://api.github.com/repos/git-for-windows/git/releases
219237
releases=$(http_get $releases_url/latest) || return
220238
download=$(echo "$releases" |
221239
grep '"browser_download_url": "' |
@@ -238,7 +256,7 @@ update_git_for_windows () {
238256
fi
239257
if test -n "$try_toast"
240258
then
241-
wintoast.exe --appname "Git for Windows" \
259+
wintoast.exe --appname "$git_label" \
242260
--appid GitForWindows.Updater \
243261
--image /mingw$bit/share/git/git-for-windows.ico \
244262
--text "Download and install $name$warn?" \

0 commit comments

Comments
 (0)