An autoupdater to keep git-for-windows up-to-date would be fantastic.
Wouldn't it? It would be as fantastic as a contribution adding this feature! :smile:
This might be an option to integrate here: https://github.com/ravibpatel/AutoUpdater.NET
When I said "contribution", I did not mean "throw a random link at the Git for Windows maintainer who is busy releasing an emergency release".
I use this function.
git-update() {
local yn="$1"
case $yn in
-\? | --?\?) echo "Usage: git-update [options]";
echo "Options:";
echo " -y, --yes Automatic yes to download and install prompt";
return;;
esac
local bit=$(ls --color=never -d /mingw* | sed 's/\/mingw//')
local releases=$(curl --silent https://api.github.com/repos/git-for-windows/git/releases/latest)
local latest=$(echo "$releases" | grep '"tag_name": "v' | sed -E 's/.*"tag_name": "v([^"]*).*/\1/')
local version=$(git --version | sed "s/git version //")
echo "Git for Windows $version (${bit}bit)"
if [ "$latest" != "$version" ]
then
echo "Update $latest is available"
local download=$(echo "$releases" | grep '"browser_download_url": "' | grep "$bit\-bit\.exe" | sed -E 's/.*": "([^"]*).*/\1/')
local filename=$(echo "$download" | sed -E 's/.*\/([^\/]*)$/\1/')
case $yn in
-[Yy]* | --[Yy]*) yn="y"; echo "Downloading $filename";;
*) read -p "Download $filename and install [N/y]? " yn;;
esac
case $yn in
[Yy]* ) curl -# -L -o $filename $download; start $filename; ps | grep bash | awk '{print "kill -9 " $2 ";" }' | sh;;
esac
return
fi
echo "Up to date"
}
UPDATE 2:
UPDATE 1:
start $filename; ps | grep 'mintty' | awk '{print $1}' | xargs kill -9 I'm able to detach the installer from the parent process and kill everthing that would prevent the installer from updating successfully. I unsure what the discussion about ConHost is about. For me killing 'mintty' processes seems to do it.Usasge
$ git-update -?
Usage: git-update [options]
Options:
-y, --yes Automatic yes to download and install prompt
Output when up to date with latest version
$ git-update
Git for Windows 2.14.0.windows.2 (64bit)
Up to date
Output when not on the latest version
$ git-update
Git for Windows 2.14.0.windows.1 (64bit)
Update 2.14.0.windows.2 is available
Download Git-2.14.0.2-64-bit.exe and install [N/y]? y
######################################################################## 100.0%
@dscho I'm very sorry! Just provided that link because I think this might be an option to implement this. I'm willing to contribute be my self or via some of my co-workers. However, I have to get familiar with the code base and installer creation first.
@between2spaces that's a nice script! A couple of suggestions:
-s option)?& so that the calling git.exe process can exit)?Indeed, nice script @between2spaces . You could launch the installer and kill the Git bash like this:
start "" "path/to/installer"
ps | grep mintty | awk '{print "kill -9 " $1 ";" }' | sh
ps | grep mintty | awk '{print "kill -9 " $1 ";" }' | sh
Nice command-line, but please keep in mind that Git Bash can be configured to be run via ConHost instead of MinTTY.
Thanks for your kind words. I've taken on board @dscho 's suggestions and updated the script (see previous post for the updated script).
The auto run of the installer is problematic. Thanks for the alternative process kill suggestion @larsxschneider, I haven't tried that yet but don't want to go down that path if "mintty" is not the right process name to be grepping for.
I've left my attempts in the updated script above, which means it's currently buggy. While it will find the latest version (and identify the correct 32/64 bit exe for your OS) and download it, the auto run of the installer currently fails. Leaving it up to the user to Cancel, find the dowloaded exe and re-run manually after ensuring all Git for Windows related processes are closed.
UPDATE: I seem to have solved the auto run using @larsxschneider's suggestion . Thought the issue about 'mintty' not always being the correct process to kill is something I'm unsure what to do about.
@between2spaces how about putting this under version control, e.g. into https://github.com/git-for-windows/build-extra/tree/master/git-extra?
@dscho Would this be more general?
ps | grep bash | awk '{print "kill -9 " $2 ";" }' | sh
Here I grep for bash and use the parent process of bash (= $2) which should be MinTTY or something else. A minor annoyance in that solution is that grep seems to invoke a second bash process. But that doesn't matter as we kill everything anyways.
@between2spaces I'd suggest making the internal variables local, to avoid inadvertently clobbering items which were set outside of the function.
--- git-update.orig 2017-08-08 12:48:05.307610800 -0500
+++ git-update 2017-08-08 12:48:58.443392900 -0500
@@ -1,21 +1,21 @@
git-update() {
- yn="$1"
+ local yn="$1"
case $yn in
-\? | --?\?) echo "Usage: git-update [options]";
echo "Options:";
echo " -y, --yes Automatic yes to download and install prompt";
return;;
esac
- releases=$(curl --silent https://api.github.com/repos/git-for-windows/git/releases/latest)
- latest=$(echo "$releases" | grep '"tag_name": "v' | sed -E 's/.*"tag_name": "v([^"]*).*/\1/')
- version=$(git --version | sed "s/git version //")
+ local releases=$(curl --silent https://api.github.com/repos/git-for-windows/git/releases/latest)
+ local latest=$(echo "$releases" | grep '"tag_name": "v' | sed -E 's/.*"tag_name": "v([^"]*).*/\1/')
+ local version=$(git --version | sed "s/git version //")
echo "Git for Windows $version"
if [ "$latest" != "$version" ]
then
echo "Update $latest is available"
- bit=$(curl -s https://git-scm.com/download/win | grep 'click here to download manually' | sed -E 's/.*-([0-9]+)-bit\.exe".*/\1/')
- download=$(echo "$releases" | grep '"browser_download_url": "' | grep "$bit\-bit\.exe" | sed -E 's/.*": "([^"]*).*/\1/')
- filename=$(echo "$download" | sed -E 's/.*\/([^\/]*)$/\1/')
+ local bit=$(curl -s https://git-scm.com/download/win | grep 'click here to download manually' | sed -E 's/.*-([0-9]+)-bit\.exe".*/\1/')
+ local download=$(echo "$releases" | grep '"browser_download_url": "' | grep "$bit\-bit\.exe" | sed -E 's/.*": "([^"]*).*/\1/')
+ local filename=$(echo "$download" | sed -E 's/.*\/([^\/]*)$/\1/')
case $yn in
-[Yy]* | --[Yy]*) yn="y";;
*) read -p "Download $filename and install [N/y]? " yn;;
@dscho Probably a good idea to put it somewhere. Is build-extra the right spot? I don't have or intend to use build-extra's.
@landstander668 Awesome. Thanks for the improvements. I've updated the function.
@larsxschneider Good idea. I tried your parent of bash idea and it seems to work. I've incorporated it into the updated function.
We are using chocolatey for managing our tools. 馃槂
I downgraded to version 2.13.3 just so I could give @between2spaces's function a try. It worked beautifully. :1st_place_medal:
Probably a good idea to put it somewhere. Is build-extra the right spot? I don't have or intend to use build-extra's.
I specifically pointed to the git-extra/ subdirectory of the build-extra repository: its contents are used to build the git-extra package and are bundled in Git for Windows, portable Git, etc
In any case, you already see from comments like this one that you need to put this script under version control ASAP so you can accept Pull Requests.
Done. Pull request https://github.com/git-for-windows/build-extra/pull/151
Thanks for the explanation @dscho on what git-extra is for. I was aware of that.
So, @bufferoverflow... a lot of your wish has already been fulfilled by others. How about giving it some love, walk the last inches of the whole nine yards and teach git update to be an auto-updater and integrate that into the installer as an option?
@dscho I will do so, my local installer asks already Daily check for available update during postinstall and a daily schtasks will then be created.
Just to clarify: I was suggesting to thank @between2spaces, @ViceIce, @landstander668 and @larsxschneider by contibuting a Pull Request that adds this option to Git for Windows' installer... I am not sure you were talking about that installer because it does not have a "Daily check for available update" function.
Dear @dscho, @between2spaces, @ViceIce, @landstander668 and @larsxschneider thank you so much for the git-update feature! I did some further work on top to integrate a scheduled task with the installer, see https://github.com/git-for-windows/build-extra/pull/153
@dscho did some enhamcements on my second PR which uses git http.proxy https://github.com/git-for-windows/build-extra/pull/155 an merged it, thank you all for making this idea a reality!
Thanx a lot to everyone who made this possible!!! Specially @bufferoverflow who triggered this.
hey folks! in a discussion on Twitter @gbraad wrote that git update might confuse users. The "update" command could easily be misinterpreted as "version control command". I agree with him.
As an alternative I think git upgrade might make sense. What do you think?
Hey all! @larsxschneider @gbraad To be sincere, I believe the best would be to trigger the update automatically by default and just ask the user if he/she wants to do it now or later. The window asking should say something like: "git client has a new version, would you like to update it now or later?" I mean this is only for the Windows client, so it would be more comfortable to have a real pop-out window asking.
I think that would be a separate discussion. I really like the explicit command for the upgrade as changing the version control system can have a severe impact (e.g. some workflows don't work anymore because of the new version of something).
I proposed the change here in a PR: https://github.com/git-for-windows/build-extra/pull/167
ok, you are right, I agree and I believe most of the people would!
Thanks! Good to see this being picked up...