X-Git-Url: https://git.exim.org/buildfarm-client.git/blobdiff_plain/8a0e7f5c13b0abdccb8445939cebd5f55d8a1916..30d73b254fe4368ec4a5a51f6b754baaa6c9f1ac:/run_branches diff --git a/run_branches b/run_branches index bf377fb..429b02e 100755 --- a/run_branches +++ b/run_branches @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl =comment @@ -78,31 +78,45 @@ $branch = 'global'; 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'; +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-updat. 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"; - die "$0: auto-update not possible: need write permissions in @{[cwd]}\n" - if not -w '.'; + $base =~ s/^\^//; - # http://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git - system("git fetch $remote") == 0 or die $? >> 8; - my ($upstream, $local, $base) = qx'git rev-parse ...@{upstream}'; die $? >> 8 if $?; - $base =~ s/^\^//; + if ($upstream ne $local) { - if ($upstream ne $local) { - die "$0: the merge base is not local anymore. Refusing to `git pull`\n" - if $base ne $local; + if ($base ne $local) { + die "the merge base is not local anymore. Refusing to `git pull`\n" + } - say "Doing git pull ..." if $verbose; + # 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"; - # if we're the merge base, the ff-only should workkkkkk - 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"; + 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"; + } } +}; + +if ($@) { + chomp $@; + warn "Automatic updated failed with `$@'\n" + ."Continue anyway\n"; } unless ( @@ -145,15 +159,12 @@ elsif ($EximBuild::conf{branches_to_build} =~ @branches = apply_throttle(@branches); -my $global_lock_dir = - $EximBuild::conf{global_lock_dir} - ||$EximBuild::conf{build_root} - ||''; +my $global_lock_dir = $EximBuild::conf{global_lock_dir} + // $EximBuild::conf{build_root} + // die "$0: need global_lock_dir\n"; -unless ($global_lock_dir && -d $global_lock_dir) -{ - die "no global lock directory: $global_lock_dir"; -} +die "$0: need r/w permissions for directory '$global_lock_dir'\n" + if not -d -w $global_lock_dir; # acquire the lock