diff options
author | Oswald Buddenhagen <oswald.buddenhagen@gmx.de> | 2019-10-20 20:05:28 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@gmx.de> | 2020-02-28 17:32:16 +0000 |
commit | d986f2eb1019a120ec75be284c2e875ec3e159a4 (patch) | |
tree | 9aa964b6e609362b3ce6a1b48479b90d9a45c555 /bin | |
parent | 947fa9dcef64ad1e51ec91a421410f6980b8fc01 (diff) | |
download | qtrepotools-d986f2eb1019a120ec75be284c2e875ec3e159a4.tar.gz |
gpush: complain about merges of non-upstream commits
this catches both the case where a regular user used git-pull without
--rebase, and where a merge master forgot that they have local commits.
cascaded proper merges are also supported, which the forward merge
monkey on duty might appreciate.
Change-Id: I67787328071c90e3ad9b03ac2a8dbec6e065db1d
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/git-gpush | 50 | ||||
-rw-r--r-- | bin/git_gpush.pm | 19 |
2 files changed, 69 insertions, 0 deletions
diff --git a/bin/git-gpush b/bin/git-gpush index 9bd5c22..2df4b59 100755 --- a/bin/git-gpush +++ b/bin/git-gpush @@ -1,5 +1,6 @@ #!/usr/bin/perl # Copyright (C) 2017 The Qt Company Ltd. +# Copyright (C) 2019 Oswald Buddenhagen # Contact: http://www.qt.io/licensing/ # # You may use this file under the terms of the 3-clause BSD license. @@ -125,6 +126,7 @@ Configuration: Copyright: Copyright (C) 2017 The Qt Company Ltd. + Copyright (C) 2019 Oswald Buddenhagen Contact: http://www.qt.io/licensing/ License: @@ -422,6 +424,53 @@ sub get_changes() return $group; } +sub check_merge($$); + +sub check_merge($$) +{ + my ($parents, $failed) = @_; + + my $good = 1; + foreach my $parentid (@$parents) { + my $parent = $commit_by_id{$parentid}; + # If the parent is upstream, the merge is good. + next if (!$parent); + + my $rparents = $$parent{parents}; + # Merges of (good) merges are also good. + next if (@$rparents > 1 && check_merge($rparents, $failed)); + + push @$failed, $parent; + $good = 0; + } + return $good; +} + +sub check_merges($) +{ + my ($group) = @_; + + foreach my $change (@{$$group{changes}}) { + my $commit = $$change{local}; + my $parents = $$commit{parents}; + if (@$parents > 1) { + my (@failed, $header); + if (!check_merge($parents, \@failed)) { + $header = ",----- Merge of non-upstream commit(s) -----\n"; + set_group_error($group, 'fixed', + "Maybe you forgot to use git pull's --rebase option?\n"); + } else { + next; + } + $$change{annotation} = ' [FAIL]'; + set_change_error($change, 'fixed', + $header.format_commits(\@failed, "| ") + ."`-------------------------------------------\n"); + fail_formatted(report_pushed_changes($group)); + } + } +} + # Assign each local Change to a matching remote Change if possible, # on the way complaining about creating duplicates. sub map_remote_changes($) @@ -661,6 +710,7 @@ sub execute_pushing() } determine_remote_branch($group); if ($online) { + check_merges($group); map_remote_changes($group); classify_changes_online($group); } elsif (!$quiet) { diff --git a/bin/git_gpush.pm b/bin/git_gpush.pm index 38d80ba..f3e394e 100644 --- a/bin/git_gpush.pm +++ b/bin/git_gpush.pm @@ -1,4 +1,5 @@ # Copyright (C) 2017 The Qt Company Ltd. +# Copyright (C) 2019 Oswald Buddenhagen # Contact: http://www.qt.io/licensing/ # # You may use this file under the terms of the 3-clause BSD license. @@ -736,6 +737,24 @@ sub format_subject($$;$) return format_id($id)." ($subject)"; } +sub format_commit($;$) +{ + my ($commit, $max) = @_; + return format_subject($$commit{changeid}, $$commit{subject}, $max); +} + +sub format_commits($;$) +{ + my ($commits, $prefix) = @_; + + $prefix = " " if (!defined($prefix)); + my $output = ""; + foreach my $commit (@$commits) { + $output .= $prefix.format_commit($commit, -length($prefix))."\n"; + } + return $output; +} + sub _unpack_report($@) { my $report = shift @_; |