summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@gmx.de>2019-10-15 17:41:23 +0200
committerOswald Buddenhagen <oswald.buddenhagen@gmx.de>2020-02-28 17:35:33 +0000
commit87c7405611750d68a1b61c071b9da7344a6a4327 (patch)
treeabf31c33f92b59e26600235faec6d341543b8de6 /bin
parentd986f2eb1019a120ec75be284c2e875ec3e159a4 (diff)
downloadqtrepotools-87c7405611750d68a1b61c071b9da7344a6a4327.tar.gz
gpush: complain about unpushed 2nd+ parents of merges
Change-Id: I4be418a43400faf3e1078e73ff6c5a48044244b6 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'bin')
-rwxr-xr-xbin/git-gpush27
-rw-r--r--bin/git_gpush.pm2
2 files changed, 29 insertions, 0 deletions
diff --git a/bin/git-gpush b/bin/git-gpush
index 2df4b59..681e19f 100755
--- a/bin/git-gpush
+++ b/bin/git-gpush
@@ -446,6 +446,23 @@ sub check_merge($$)
return $good;
}
+# Ensure that we don't implicitly create new PatchSets for non-1st
+# parents of merges, as these would most likely target the wrong branch.
+# TODO: this could be handled more nicely by doing recursive pushes
+# instead of bailing out.
+sub parents_pushed($$)
+{
+ my ($parents, $failed) = @_;
+
+ foreach my $parentid (@$parents[1 .. $#$parents]) {
+ next if (defined($gerrit_info_by_sha1{$parentid})); # Gerrit knows it
+ my $parent = $commit_by_id{$parentid};
+ next if (!$parent); # Already upstream
+ push @$failed, $parent;
+ }
+ return !@$failed;
+}
+
sub check_merges($)
{
my ($group) = @_;
@@ -459,6 +476,9 @@ sub check_merges($)
$header = ",----- Merge of non-upstream commit(s) -----\n";
set_group_error($group, 'fixed',
"Maybe you forgot to use git pull's --rebase option?\n");
+ } elsif (!parents_pushed($parents, \@failed)) {
+ $header = ",----- Parent merge(s) not pushed yet ------\n";
+ set_group_error($group, 'fixed', "Please push the parent(s) first.\n");
} else {
next;
}
@@ -706,6 +726,13 @@ sub execute_pushing()
my $pushed_changes = $$group{changes};
if ($online) {
my @queries = map { "change:".$$_{id} } @$pushed_changes;
+ push @queries,
+ map { "commit:".$_ }
+ # Only ones that are not upstream yet.
+ grep { $commit_by_id{$_} }
+ # Only 2nd+ parents of local commits.
+ map { @$_ > 1 ? @$_[1 .. $#$_] : () }
+ map { $$_{local}{parents} } @$pushed_changes;
query_gerrit(\@queries);
}
determine_remote_branch($group);
diff --git a/bin/git_gpush.pm b/bin/git_gpush.pm
index f3e394e..09a733d 100644
--- a/bin/git_gpush.pm
+++ b/bin/git_gpush.pm
@@ -479,6 +479,7 @@ sub changes_from_commits($)
########################
our %gerrit_info_by_key;
+our %gerrit_info_by_sha1;
our %gerrit_infos_by_id;
##################
@@ -1088,6 +1089,7 @@ sub query_gerrit($;$)
);
$revs[$number] = \%rev;
$rev_map{$revision} = \%rev;
+ $gerrit_info_by_sha1{$revision} = $ginfo;
}
$$ginfo{id} = $changeid;
$$ginfo{status} = $status;