Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoupdater to keep git up-to-date #1256

Closed
1 task done
bufferoverflow opened this issue Aug 5, 2017 · 29 comments
Closed
1 task done

autoupdater to keep git up-to-date #1256

bufferoverflow opened this issue Aug 5, 2017 · 29 comments

Comments

@bufferoverflow
Copy link

  • I was not able to find an open or closed issue matching what I'm seeing

Setup

  • Windows Installer 32-bit and 64-bit

Details

  • An autoupdater to keep git-for-windows up-to-date would be fantastic.
@dscho
Copy link
Member

dscho commented Aug 5, 2017

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! 😄

@bufferoverflow
Copy link
Author

This might be an option to integrate here: https://github.com/ravibpatel/AutoUpdater.NET

@dscho
Copy link
Member

dscho commented Aug 7, 2017

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".

@ghost
Copy link

ghost commented Aug 7, 2017

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:

  • Made all variables local as suggested by @landstander668
  • Bit version now determined from existence of /mingw(32|64) instead of git-scm.com
  • Changed process kills to @larsxschneider's updated parent of bash idea

UPDATE 1:

  • Now uses the github repos releases URL to find the most up to date release thanks to @dscho
  • Still using the git-scm.com URL to find out what bit version to download (open to suggestions on how to find this out without needing to hit a second URL)
  • As was suggested by @dscho I've turned off the verbose download progress, and instead switch to a # progress bar because slow connections (like my home ADSL 2) take a lot longer than few seconds to download.
  • As suggested by @dscho and @larsxschneider I added the auto run of the installer after download. Using a combination of 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%

@bufferoverflow
Copy link
Author

@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.

@dscho
Copy link
Member

dscho commented Aug 7, 2017

@between2spaces that's a nice script! A couple of suggestions:

@larsxschneider
Copy link
Member

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

@dscho
Copy link
Member

dscho commented Aug 7, 2017

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.

@ghost
Copy link

ghost commented Aug 8, 2017

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.

@dscho
Copy link
Member

dscho commented Aug 8, 2017

@between2spaces how about putting this under version control, e.g. into https://github.com/git-for-windows/build-extra/tree/master/git-extra?

@larsxschneider
Copy link
Member

@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.

@landstander668
Copy link

@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;;

@ghost
Copy link

ghost commented Aug 8, 2017

@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.

@viceice
Copy link

viceice commented Aug 9, 2017

We are using chocolatey for managing our tools. 😃

@landstander668
Copy link

I downgraded to version 2.13.3 just so I could give @between2spaces's function a try. It worked beautifully. 🥇

@dscho
Copy link
Member

dscho commented Aug 9, 2017

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.

@ghost
Copy link

ghost commented Aug 10, 2017

Done. Pull request git-for-windows/build-extra#151

Thanks for the explanation @dscho on what git-extra is for. I was aware of that.

@dscho
Copy link
Member

dscho commented Aug 22, 2017

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?

@bufferoverflow
Copy link
Author

@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.

@dscho
Copy link
Member

dscho commented Aug 23, 2017

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.

@bufferoverflow
Copy link
Author

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 git-for-windows/build-extra#153

@bufferoverflow
Copy link
Author

@dscho did some enhamcements on my second PR which uses git http.proxy git-for-windows/build-extra#155 an merged it, thank you all for making this idea a reality!

@garzaj
Copy link

garzaj commented Jan 8, 2018

Thanx a lot to everyone who made this possible!!! Specially @bufferoverflow who triggered this.

@larsxschneider
Copy link
Member

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?

@garzaj
Copy link

garzaj commented Jan 17, 2018

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.

@larsxschneider
Copy link
Member

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).

@larsxschneider
Copy link
Member

I proposed the change here in a PR: git-for-windows/build-extra#167

@garzaj
Copy link

garzaj commented Jan 17, 2018

ok, you are right, I agree and I believe most of the people would!

@gbraad
Copy link

gbraad commented Jan 17, 2018

Thanks! Good to see this being picked up...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants