-
Notifications
You must be signed in to change notification settings - Fork 6
/
git-backport
executable file
·81 lines (58 loc) · 2.17 KB
/
git-backport
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
#!/usr/bin/perl
#
# This backports work on a branch off main into
# earlier stable branches of moodle.
use strict;
if (!$ARGV[0]) {
print "git backport name-of-feature-of-main MOODLE_29_STABLE [more branches]\n";
exit;
}
my $feature = shift @ARGV;
my @onto = @ARGV;
my $githubrepo = `git config --get user.github`;
print "Feature = $feature \n";
`git checkout $feature`;
foreach my $onto (@onto) {
my $ontobranch = $feature . '-' . $onto;
my $cmd;
print "Onto $onto $ontobranch \n";
# Just make sure cherry pick state is clean
$cmd = "git cherry-pick --abort";
# print "$cmd\n"; `$cmd`;
`$cmd`;
print "-------------------------------------------------\n";
# Jump onto main temporarily
$cmd ="git checkout main";
print "$cmd\n"; `$cmd`;
print "-------------------------------------------------\n";
# Make sure it's up to date
$cmd ="git pull origin";
print "$cmd\n"; `$cmd`;
print "-------------------------------------------------\n";
# Remove the backport branch if it exists
$cmd ="git branch -D $ontobranch";
print "$cmd\n"; `$cmd`;
print "-------------------------------------------------\n";
# Start a new branch from the stable branch
$cmd = "git branch $ontobranch origin/$onto";
print "$cmd\n"; `$cmd`;
print "-------------------------------------------------\n";
# Checkout new branch
$cmd = "git checkout $ontobranch";
print "$cmd\n"; `$cmd`;
print "-------------------------------------------------\n";
# `git pull upstream $ontobranch`;
# Graft the diff new stuff on feature from main, onto new stable branch
# `git rebase --onto $ontobranch $feature origin/$onto `;
$cmd = "git cherry-pick main..$feature";
print "$cmd\n"; `$cmd`;
print "-------------------------------------------------\n";
$cmd = "git push -f brendan";
print "$cmd\n"; `$cmd`;
print "\n\nDiff url https://github.com/moodle/moodle/compare/$onto...$githubrepo:$ontobranch\n\n"
}
# Now go back to where we started
my $cmd = "git checkout $feature";
print "$cmd\n"; `$cmd`;
print "-------------------------------------------------\n";
# `git checkout $branch`;