-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathav-merge-branch
executable file
·65 lines (48 loc) · 1.78 KB
/
av-merge-branch
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
#!/usr/bin/env perl
use warnings;
use strict;
use feature qw/say/;
use Git::Repository;
use Getopt::Long;
use lib::abs 'lib';
use Git::WorkFlow::AstraVer::Branch qw/list_branches_sorted check_branch_empty/;
use Git::WorkFlow::AstraVer::Repo qw/check_changes_exist/;
BEGIN {
eval {
require Smart::Comments;
Smart::Comments->import();
}
}
if ((!@ARGV) || (($ARGV[0] ne '--spec') && ($ARGV[0] ne '--devel'))) {
die "$0 <--devel|--spec>\n"
}
my $branch = substr $ARGV[0], 2; # branch merge into
my $r = Git::Repository->new(work_tree => $ENV{CURRENT_PROJECT});
if (check_changes_exist($r)) {
die "There are changes in repository. You should commit/remove them first.\n";
}
my @branches = list_branches_sorted($r, $branch . '-*');
die "Can't find versioned branches $branch\n"
unless @branches;
my $lbranch = $branches[-1];
die "Can't determine previous versioned branch of development.\n"
unless $lbranch;
my $parent_branch = $branch eq 'devel' ? 'master' : $lbranch =~ s/\Aspec/devel/r;
warn "$lbranch have no commits since $parent_branch\n"
if check_branch_empty($r, $parent_branch, $lbranch);
$r->run(checkout => $branch);
my $merge_msg = "Merge branch '$lbranch' into $branch";
my $sha = $r->run('commit-tree' => '-m' => $merge_msg => '-p' => 'HEAD' => '-p' => $lbranch => "$lbranch:");
$r->run('update-ref' => 'HEAD' => $sha);
$r->run(qw/reset --hard/);
say $merge_msg;
#
#git merge -s ours ref-to-be-merged
#git diff --binary ref-to-be-merged | git apply -R --index
#git commit -F .git/COMMIT_EDITMSG --amend
#
#git checkout -b tmp origin/upstream
#git merge -s ours downstream # ignoring all changes from downstream
#git checkout downstream
#git merge tmp # fast-forward to tmp HEAD
#git branch -D tmp # deleting tmp