forked from levic/pve-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepoid.pl
executable file
·40 lines (27 loc) · 825 Bytes
/
repoid.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
#!/usr/bin/perl -w
# use use the first 8 characters from the master commit ID
# git status --porcelain
use strict;
use lib qw(.);
use PVE::Tools qw(run_command);
my $gitdir = shift;
die "no repository" if !$gitdir;
my $path = "$gitdir/refs/heads/master";
die "master branch does not exists" if ! -f $path;
my $arg1 = shift;
if ($arg1) {
die "unknown parameter '$arg1'" if $arg1 ne 'check';
my $testfunc = sub {
my $line = shift;
return if $line =~ m/^#/;
return if $line =~ m/^\?\?/;
die "detected modified content: $line\n";
};
my $cmd = ['git', '--git-dir', $gitdir ,'status', '--porcelain'];
run_command($cmd, outfunc => $testfunc);
}
my $repoid = `cat $path`;
chomp $repoid;
die "invalid commit format" if $repoid !~ m/^[0-9a-f]{40}$/;
my $res = substr $repoid, 0, 8;
print "$res\n";