-if (not exists $EximBuild::Conf{auto_update} or $EximBuild::Conf{auto_update})
-{
- 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;
- my ($upstream, $local, $base) = qx'git rev-parse ...@{upstream}'; die $? >> 8 if $?;
- $base =~ s/^\^//;
-
- if ($upstream ne $local) {
- die "$0: the merge base is not local anymore. Refusing to `git pull`\n"
- if $base ne $local;
-
- # if we're the merge base, the ff-only should workkkkkk
- system 'git pull --ff-only'
+eval {
+ if (not exists $EximBuild::conf{auto_update} or $EximBuild::conf{auto_update})
+ {
+ my $remote = $EximBuild::conf{auto_update} // 'origin';
+
+ die "auto-update not possible: need write permissions in @{[cwd]}\n"
+ if not -w '.';
+
+ # Get information about our remote and calculate the chance for a
+ # successfull auto-update. Based on:
+ # http://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git
+ system("git fetch $remote") == 0 or die "'git fetch $remote' failed\n";
+ my ($upstream, $local, $base) = qx'git rev-parse ...@{upstream}' or die "'git rev-parse' failed\n";
+
+ $base =~ s/^\^//;
+
+ if ($upstream ne $local) {
+
+ if ($base ne $local) {
+ die "the merge base is not local anymore. Refusing to `git pull`\n"
+ }
+
+ # if we're the merge base, the ff-only should work
+ # except if there are local changes. We won't stop, if we
+ # fail to update, but we'll issue a warning
+ system("git pull --ff-only $remote") == 0 or die "git pull --ff-only\n";
+
+ say "re-execute after update";
+ chdir $CALLED{cwd} or die "Can't chdir to $CALLED{cwd}: $!\n";
+ exec $CALLED{argv0}, @{$CALLED{argv}};
+ die "Can't re-exec\n";
+ }