From 977f0841e46f9a4249526f93cbfbf540210c76e6 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 25 Nov 2016 20:03:24 +0100 Subject: [PATCH] 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 --- init-repository | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/init-repository b/init-repository index 52efb201..5c76a31c 100755 --- a/init-repository +++ b/init-repository @@ -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) = @_;