-
Notifications
You must be signed in to change notification settings - Fork 8
/
sabayon-commit
95 lines (83 loc) · 2.85 KB
/
sabayon-commit
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
#!/usr/bin/perl
# Copyright 2016-2018 See AUTHORS file
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use feature 'say';
use Cwd;
use File::Temp;
my $current_git_directory = qx|git rev-parse --show-toplevel 2>/dev/null|;
chomp $current_git_directory;
my $cwd = getcwd;
chdir($current_git_directory);
my $commit_message_tmpfile = File::Temp->new();
my @changed_files = qx|git status -s|;
my $n_changed_files = scalar @changed_files;
die "No files changed. Exiting." if $n_changed_files <= 0;
my %atoms = ();
sub _build_git_repo {
my ($file_name) = @_;
my $commit_message;
if ( $file_name
=~ /conf\/(home|intel|arm(arch|hfp|v6l|vtl))\/(entropy|portage|repo)\/(.*)/
)
{
$commit_message = "$1/$4: ";
}
elsif ( $filename eq
"conf/noarch/entropy/packages/packages.server.dep_blacklist" )
{
$commit_message = "dep_blacklist: ";
}
elsif ( $filename eq
"conf/noarch/entropy/packages/packages.server.dep_rewrite" )
{
$commit_message = "dep_rewrite: ";
}
if ($commit_message) {
print $commit_message_tmpfile $commit_message;
system( "git commit -eF " . $commit_message_tmpfile->filename );
unlink($commit_message_tmpfile) if -e $commit_message_tmpfile;
}
}
sub _overlay_git_repo {
die "If you are in the overlay, call me in the ebuild dir"
if $current_git_directory eq getcwd;
chdir($cwd);
die "I'm not pleased.. but you could force with --force"
if ( _system("repoman") && $ARGV[0] ne "--force" );
_system("repoman commit $ARGV[0]");
}
sub _system {
my $prog = shift;
my $rv = system( {$prog} $prog => @_ );
if ( $rv == -1 ) { say("Can't launch $prog: $!"); return 1; }
elsif ( my $s = $rv & 127 ) {
say("$prog died from signal $s");
return 1;
}
elsif ( my $e = $rv >> 8 ) { say("$prog exited with code $e"); return 1; }
return 0;
}
foreach my $file (@changed_files) {
chomp $file;
my @words = split( ' ', $file, 2 );
next if $words[0] eq "??"; # allow "dangling" files
my $file_name = $words[1];
if ( $file_name =~ /conf\/(intel|arm|noarch)/ ) {
_build_git_repo($file_name);
}
elsif ( $file_name =~ /\.ebuild/ ) {
_overlay_git_repo($file_name);
}
}