refuse to operate with dirty submodules

the operation would later error out anyway, after spending a lot of time
fetching the remotes, and leaving a partially updated state behind.

Change-Id: Ib2a688e446a9bd4ba3b15fc73082224433c18388
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Oswald Buddenhagen
2016-11-25 20:03:24 +01:00
parent 75f605743c
commit 977f0841e4

View File

@@ -395,6 +395,14 @@ sub git_clone_all_submodules
}
}
my $any_bad = 0;
foreach my $module (@modules) {
$any_bad = 1
if ($self->git_stat_one_submodule($subdirs{$module}));
}
die("Dirty submodule(s) present; cannot proceed.\n")
if ($any_bad);
foreach my $module (@modules) {
$self->git_clone_one_submodule($subdirs{$module}, $subbases{$module},
$co_branch && $subbranches{$module});
@@ -452,6 +460,26 @@ sub git_add_remotes
$self->exe('git', 'config', 'remote.gerrit.fetch', '+refs/heads/*:refs/remotes/gerrit/*', '/heads/');
}
sub git_stat_one_submodule
{
my ($self, $submodule) = @_;
return 0 if (! -e "$submodule/.git");
my $orig_cwd = getcwd();
chdir($submodule) or confess "chdir $submodule: $OS_ERROR";
my @sts = qx(git status --porcelain --untracked=no);
chdir($orig_cwd) or confess "cd $orig_cwd: $OS_ERROR";
return 0 if (!@sts);
print STDERR "$submodule is dirty.\n";
return -1;
}
sub git_clone_one_submodule
{
my ($self, $submodule, $repo_basename, $branch) = @_;