-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_last_commit.pl
More file actions
executable file
·42 lines (40 loc) · 1.12 KB
/
get_last_commit.pl
File metadata and controls
executable file
·42 lines (40 loc) · 1.12 KB
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
#!/bin/perl
my $folder = $ARGV[0];
my $full_folder = "";
if($folder =~ /^\//){
$full_folder = $folder;
}
else{
$full_folder = `pwd`."/".$folder;
}
$full_folder =~ s/\n//;
my @git_list=`find $full_folder -type d -name '.git' | grep -v repo`;
my $last_id = "";
my $last_time = "";
my $short_dir = "";
if( -f "$full_folder/revision.sh" ){
system("rm $full_folder/revision.sh");
}
foreach my $gl (0..$#git_list)
{
#print $git_list[$gl]."\n";
my $project_dir = substr $git_list[$gl], 0, -5;
#print "real dir: $project_dir\n";
if($project_dir =~ /$folder\/(.+?)$/)
{
$short_dir = $1;
}
chdir($project_dir) or die "$!";
my $commitID = `git log -n 1 --format="%H"`;
$commitID =~ s/\n//g;
my $cmd = "echo \"cd $short_dir\ngit checkout -f $commitID\ncd -\" >> $full_folder/revision.sh";
#print "command: $cmd\n";
system($cmd);
my $commitTime = `git log -n 1 --format="%ct"`;
if( $last_time eq "" || $last_time < $commitTime)
{
$last_time = $commitTime;
$last_id = $commitID;
}
}
print substr($last_id,0,7)."\n";