-
Notifications
You must be signed in to change notification settings - Fork 138
/
merge_pull_request.pl
executable file
·100 lines (72 loc) · 2.55 KB
/
merge_pull_request.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#! perl
# Copyright (C) 2011-2012, Parrot Foundation.
use strict;
use warnings;
use autodie qw/:all/;
=head1 NAME
tools/dev/merge_pull_request.pl - Merge Github Pull Requests
=head1 SYNOPSIS
The typical workflow to merge a pull request into parrot.git
# merge pull request #123 into current branch
perl tools/dev/merge_pull_request.pl 123
# this creates the branch pull_request_123
make test # etc...
=head1 DESCRIPTION
This script implements Parrot's merge of github pull requests.
=head1 SQUASHING COMMITS
If the pull request has lots of extraneous commits, you may want
to "squash" them into one commit. If you want to squash the last
five commits:
git rebase -i HEAD~5
This will open up your editor. Follow the instructions for squashing commits
together.
# If the pull request is ready to be merged to master
git checkout master
git merge --no-ff pull_request_123
git push
git branch -d pull_request_123
# If working copy changed were stashed (the script will notify you)
# pop those back off the stash
git stash pop
This script can be used to merge a pull request for any repo in the
Parrot Github Organization. For instance, to merge Cardinal Pull
request #4:
perl $PARROT/tools/dev/merge_pull_request.pl 4 cardinal
If you do not want the default branch name, you can specify a third
argument to specify one:
perl $PARROT/tools/dev/merge_pull_request.pl 4 cardinal awesome_feature
This will merge pull request #4 in the cardinal repo into a branch
called 'awesome_feature'.
=cut
my $num = shift or die "Must give a pull request number to merge!";
my $repo = shift || 'parrot';
my $merge_branch = shift;
merge_pull_request($num, $repo, $merge_branch);
sub merge_pull_request {
my ($num, $repo, $merge_branch) = @_;
$merge_branch ||= "pull_request_$num";
chomp( my $branch = qx{ git rev-parse --symbolic-full-name HEAD } );
my $status = qx{ git status -u };
system("git checkout -b $merge_branch");
my $stashed = stash_if_necessary($repo, $status);
system("wget --no-check-certificate https://github.com/parrot/$repo/pull/$num.patch");
system("git am --signoff $num.patch");
}
sub stash_if_necessary {
my ($repo, $status) = @_;
unless ($status =~ m/(nothing to commit|nothing added to commit)/) {
print "Stashing work in $repo\n";
system("git stash");
return 1;
}
else {
print "Nothing to stash in $repo\n";
return 0;
}
}
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: