Re-exec after auto update
authorHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>
Sat, 5 Nov 2016 23:09:37 +0000 (00:09 +0100)
committerHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>
Sat, 5 Nov 2016 23:09:37 +0000 (00:09 +0100)
run_branches

index 20f37902519f25f30d7c802923668fde3162b750..bf377fbfdb4e9e92e08910038baa69b4e93bd321 100755 (executable)
@@ -34,6 +34,11 @@ if ($0 =~ /(.*)\.pl$/) {
 
 # Most of the client code assumes that our working directory
 # is the client code directory.
+my %CALLED = (
+    cwd => cwd(),
+    argv0 => $0,
+    argv => [@ARGV],   # get a copy!
+);
 chdir $RealBin or die "$0: Can't chdir to '$RealBin': $!\n";
 say "Changed working directory to '$RealBin'" if -t;
 
@@ -75,10 +80,13 @@ require $buildconf;
 # Check if auto-update is wanted and possible
 if (not exists $EximBuild::Conf{auto_update} or $EximBuild::Conf{auto_update})
 {
+    my $remote = $EximBuild::Conf{auto_update} // 'origin';
+
     die "$0: auto-update not possible: need write permissions in @{[cwd]}\n"
        if not -w '.';
+
     # http://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git
-    system('git remote update') == 0 or die $? >> 8;
+    system("git fetch $remote") == 0 or die $? >> 8;
     my ($upstream, $local, $base) = qx'git rev-parse ...@{upstream}';   die $? >> 8 if $?;
     $base =~ s/^\^//;
 
@@ -86,8 +94,14 @@ if (not exists $EximBuild::Conf{auto_update} or $EximBuild::Conf{auto_update})
        die "$0: the merge base is not local anymore. Refusing to `git pull`\n"
            if $base ne $local;
 
+       say "Doing git pull ..." if $verbose;
+
        # if we're the merge base, the ff-only should workkkkkk
-       system 'git pull --ff-only'
+       system 'git pull --ff-only' == 0 or die $? >> 8;
+       say "$0: re-execute after update";
+       chdir $CALLED{cwd} or die "$0: Can't chdir to $CALLED{cwd}: $!\n";
+       exec $CALLED{argv0}, @{$CALLED{argv}};
+       die "Can't re-exec\n";
     }
 }