line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
36883
|
use strict; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
25
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Git::Helpers; |
5
|
|
|
|
|
|
|
our $VERSION = '1.000000'; |
6
|
1
|
|
|
1
|
|
5
|
use Carp qw( croak ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
49
|
|
7
|
1
|
|
|
1
|
|
6
|
use Capture::Tiny 'capture_stderr'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
41
|
|
8
|
1
|
|
|
1
|
|
400
|
use File::pushd qw( pushd ); |
|
1
|
|
|
|
|
977
|
|
|
1
|
|
|
|
|
45
|
|
9
|
1
|
|
|
1
|
|
375
|
use Git::Sub; |
|
1
|
|
|
|
|
33985
|
|
|
1
|
|
|
|
|
7
|
|
10
|
1
|
|
|
|
|
9
|
use Sub::Exporter -setup => { |
11
|
|
|
|
|
|
|
exports => [ |
12
|
|
|
|
|
|
|
'checkout_root', |
13
|
|
|
|
|
|
|
'current_branch_name', |
14
|
|
|
|
|
|
|
'https_remote_url', |
15
|
|
|
|
|
|
|
'ignored_files', |
16
|
|
|
|
|
|
|
'is_inside_work_tree', |
17
|
|
|
|
|
|
|
'remote_url', |
18
|
|
|
|
|
|
|
] |
19
|
1
|
|
|
1
|
|
528
|
}; |
|
1
|
|
|
|
|
9743
|
|
20
|
1
|
|
|
1
|
|
823
|
use Try::Tiny qw( catch try ); |
|
1
|
|
|
|
|
1171
|
|
|
1
|
|
|
|
|
46
|
|
21
|
1
|
|
|
1
|
|
543
|
use URI (); |
|
1
|
|
|
|
|
3802
|
|
|
1
|
|
|
|
|
24
|
|
22
|
1
|
|
|
1
|
|
392
|
use URI::FromHash qw( uri ); |
|
1
|
|
|
|
|
6866
|
|
|
1
|
|
|
|
|
68
|
|
23
|
1
|
|
|
1
|
|
408
|
use URI::Heuristic qw(uf_uristr); |
|
1
|
|
|
|
|
1475
|
|
|
1
|
|
|
|
|
46
|
|
24
|
1
|
|
|
1
|
|
339
|
use URI::git (); |
|
1
|
|
|
|
|
6709
|
|
|
1
|
|
|
|
|
475
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub checkout_root { |
27
|
3
|
|
|
3
|
1
|
115468
|
my $dir = shift; |
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
|
|
14
|
my ( $new_dir, $root ); |
30
|
3
|
100
|
|
|
|
44
|
$new_dir = pushd($dir) if $dir; |
31
|
3
|
|
100
|
|
|
301
|
$dir ||= '.'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# the exception thrown by rev-parse when we're not in a repo is not |
34
|
|
|
|
|
|
|
# very helpful (see following), so just ditch it in favor of the error |
35
|
|
|
|
|
|
|
# output. |
36
|
|
|
|
|
|
|
# "rev_parse error 128 at /home/maxmind/perl5/lib/perl5/Git/Helpers.pm line 30" |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $stderr = capture_stderr { |
39
|
3
|
|
|
|
|
183
|
try { $root = scalar git::rev_parse qw(--show-toplevel) } |
40
|
3
|
|
|
3
|
|
183
|
}; |
|
3
|
|
|
|
|
3056
|
|
41
|
3
|
100
|
|
|
|
30913
|
croak "Error in $dir: $stderr" |
42
|
|
|
|
|
|
|
if $stderr; |
43
|
|
|
|
|
|
|
|
44
|
2
|
|
|
|
|
44
|
return $root; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Works as of 1.6.3:1 |
48
|
|
|
|
|
|
|
# http://stackoverflow.com/questions/1417957/show-just-the-current-branch-in-git |
49
|
|
|
|
|
|
|
sub current_branch_name { |
50
|
1
|
|
|
1
|
1
|
131731
|
return git::rev_parse( '--abbrev-ref', 'HEAD' ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub https_remote_url { |
54
|
2
|
|
|
2
|
1
|
15
|
my $remote_url = remote_url(shift); |
55
|
2
|
100
|
|
|
|
51
|
return undef unless $remote_url; |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
10
|
my $branch = shift; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# remove trailing .git |
60
|
1
|
|
|
|
|
18
|
$remote_url =~ s{\.git\z}{}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# remove 'git@' from git@github.com:username/repo.git |
63
|
1
|
|
|
|
|
13
|
$remote_url =~ s{\w*\@}{}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# remove : from git@github.com:username/repo.git |
66
|
1
|
|
|
|
|
28
|
$remote_url =~ s{(\w):(\w)}{$1/$2}; |
67
|
|
|
|
|
|
|
|
68
|
1
|
50
|
|
|
|
9
|
if ($branch) { |
69
|
0
|
|
|
|
|
0
|
$remote_url .= '/tree/' . current_branch_name(); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
21
|
my $uri = URI->new( uf_uristr($remote_url) ); |
73
|
1
|
|
|
|
|
1853
|
$uri->scheme('https'); |
74
|
1
|
|
|
|
|
1083
|
return $uri; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub is_inside_work_tree { |
78
|
2
|
|
|
2
|
1
|
11755
|
my $success; |
79
|
|
|
|
|
|
|
capture_stderr { |
80
|
|
|
|
|
|
|
try { |
81
|
2
|
|
|
|
|
127
|
$success = git::rev_parse('--is-inside-work-tree'); |
82
|
2
|
|
|
2
|
|
1965
|
}; |
83
|
2
|
|
|
|
|
104
|
}; |
84
|
2
|
|
|
|
|
19438
|
return $success; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub ignored_files { |
88
|
5
|
|
100
|
5
|
1
|
4029
|
my $dir = shift || '.'; |
89
|
5
|
|
|
|
|
16
|
my @success; |
90
|
|
|
|
|
|
|
my $stderr = capture_stderr { |
91
|
|
|
|
|
|
|
try { |
92
|
5
|
|
|
|
|
237
|
@success = git::ls_files( |
93
|
|
|
|
|
|
|
$dir, '--ignored', '--exclude-standard', |
94
|
|
|
|
|
|
|
'--others' |
95
|
|
|
|
|
|
|
); |
96
|
5
|
|
|
5
|
|
4591
|
}; |
97
|
5
|
|
|
|
|
194
|
}; |
98
|
|
|
|
|
|
|
|
99
|
5
|
100
|
|
|
|
50279
|
croak "Cannot find ignored files in dir: $stderr" if $stderr; |
100
|
|
|
|
|
|
|
|
101
|
4
|
|
50
|
|
|
157
|
return \@success || []; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub remote_url { |
105
|
3
|
|
50
|
3
|
1
|
35638
|
my $remote = shift || 'origin'; |
106
|
3
|
|
|
|
|
15
|
my $url; |
107
|
|
|
|
|
|
|
my $stderr = capture_stderr { |
108
|
|
|
|
|
|
|
try { |
109
|
3
|
|
|
|
|
325
|
$url = git::remote( 'get-url', $remote ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
catch { |
113
|
|
|
|
|
|
|
try { |
114
|
1
|
|
|
|
|
64
|
$url = git::config( '--get', "remote.$remote.url" ); |
115
|
1
|
|
|
|
|
9808
|
}; |
116
|
|
|
|
|
|
|
} |
117
|
3
|
|
|
3
|
|
130
|
}; |
|
3
|
|
|
|
|
3348
|
|
118
|
|
|
|
|
|
|
|
119
|
3
|
|
|
|
|
30874
|
return $url; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#ABSTRACT: Shortcuts for common Git commands |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |