line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
546
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Cogit::Util; |
5
|
|
|
|
|
|
|
$Cogit::Util::VERSION = '0.001001'; |
6
|
1
|
|
|
|
|
13
|
use Sub::Exporter::Progressive -setup => { |
7
|
|
|
|
|
|
|
exports => [qw( current_git_dir find_git_dir is_git_dir )], |
8
|
|
|
|
|
|
|
groups => {default => [qw( current_git_dir )],}, |
9
|
1
|
|
|
1
|
|
4
|
}; |
|
1
|
|
|
|
|
1
|
|
10
|
1
|
|
|
1
|
|
161
|
use Path::Class qw( dir ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
182
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub is_git_dir { |
15
|
29
|
|
|
29
|
1
|
175
|
my ($dir) = @_; |
16
|
29
|
100
|
|
|
|
49
|
return if not -e $dir->subdir('objects'); |
17
|
13
|
50
|
|
|
|
600
|
return if not -e $dir->subdir('refs'); |
18
|
13
|
50
|
|
|
|
567
|
return if not -e $dir->file('HEAD'); |
19
|
13
|
|
|
|
|
1157
|
return 1; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub find_git_dir { |
24
|
22
|
|
|
22
|
1
|
11456
|
my $start = shift; |
25
|
|
|
|
|
|
|
|
26
|
22
|
100
|
|
|
|
36
|
return $start if is_git_dir($start); |
27
|
|
|
|
|
|
|
|
28
|
16
|
|
|
|
|
979
|
my $repodir = $start->subdir('.git'); |
29
|
|
|
|
|
|
|
|
30
|
16
|
100
|
66
|
|
|
398
|
return $repodir if -e $repodir and is_git_dir($repodir); |
31
|
|
|
|
|
|
|
|
32
|
9
|
50
|
|
|
|
233
|
return find_git_dir($start->parent) |
33
|
|
|
|
|
|
|
if $start->parent->absolute ne $start->absolute; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
return undef; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub current_git_dir { |
40
|
1
|
|
|
1
|
1
|
667
|
return find_git_dir(dir('.')); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=pod |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=encoding UTF-8 |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 NAME |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Cogit::Util |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 VERSION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
version 0.001001 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SYNOPSIS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
use Cogit::Util; |
62
|
|
|
|
|
|
|
use Cogit; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $repo = Cogit->new( |
65
|
|
|
|
|
|
|
gitdir => current_git_dir(), |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 FUNCTIONS |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 is_git_dir |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Determines if the given C<$dir> has the basic requirements of a Git repository dir. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
( ie: either a checkouts C<.git> folder, or a bare repository ) |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
if ( is_git_dir( $dir ) ) { |
77
|
|
|
|
|
|
|
... |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 find_git_dir |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $dir = find_git_dir( $subdir ); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Finds the closest C<.git> or bare tree that is either at C<$subdir> or somewhere above C<$subdir> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
If C<$subdir> is inside a 'bare' repo, returns the path to that repo. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
If C<$subdir> is inside a checkout, returns the path to the checkouts C<.git> dir. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
If C<$subdir> is not inside a git repo, returns a false value. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 current_git_dir |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Finds the closest C<.git> or bare tree by walking up parents. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my $git_dir = current_git_dir(); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
If C<$CWD> is inside a bare repo somewhere, it will return the path to the bare repo root directory. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
If C<$CWD> is inside a git checkout, it will return the path to the C<.git> folder of that checkout. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
If C<$CWD> is not inside any recognisable git repo, will return a false value. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHOR |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Arthur Axel "fREW" Schmidt <cogit@afoolishmanifesto.com> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Arthur Axel "fREW" Schmidt. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
113
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |