line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
51696
|
use strict; |
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
44
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
87
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Git::Helpers; |
5
|
|
|
|
|
|
|
our $VERSION = '1.000001'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Carp qw( croak ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
8
|
1
|
|
|
1
|
|
6
|
use Capture::Tiny qw( capture_stderr ); |
|
1
|
|
|
|
|
19
|
|
|
1
|
|
|
|
|
51
|
|
9
|
1
|
|
|
1
|
|
482
|
use File::pushd qw( pushd ); |
|
1
|
|
|
|
|
1350
|
|
|
1
|
|
|
|
|
56
|
|
10
|
1
|
|
|
1
|
|
445
|
use Git::Sub; |
|
1
|
|
|
|
|
45498
|
|
|
1
|
|
|
|
|
8
|
|
11
|
1
|
|
|
|
|
16
|
use Sub::Exporter -setup => { |
12
|
|
|
|
|
|
|
exports => [ |
13
|
|
|
|
|
|
|
'checkout_root', |
14
|
|
|
|
|
|
|
'current_branch_name', |
15
|
|
|
|
|
|
|
'https_remote_url', |
16
|
|
|
|
|
|
|
'ignored_files', |
17
|
|
|
|
|
|
|
'is_inside_work_tree', |
18
|
|
|
|
|
|
|
'remote_url', |
19
|
|
|
|
|
|
|
] |
20
|
1
|
|
|
1
|
|
748
|
}; |
|
1
|
|
|
|
|
12752
|
|
21
|
1
|
|
|
1
|
|
1131
|
use Try::Tiny qw( catch try ); |
|
1
|
|
|
|
|
1542
|
|
|
1
|
|
|
|
|
63
|
|
22
|
1
|
|
|
1
|
|
1686
|
use URI (); |
|
1
|
|
|
|
|
5302
|
|
|
1
|
|
|
|
|
38
|
|
23
|
1
|
|
|
1
|
|
643
|
use URI::Heuristic qw( uf_uristr ); |
|
1
|
|
|
|
|
1907
|
|
|
1
|
|
|
|
|
91
|
|
24
|
1
|
|
|
1
|
|
468
|
use URI::git (); |
|
1
|
|
|
|
|
10954
|
|
|
1
|
|
|
|
|
700
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub checkout_root { |
27
|
3
|
|
|
3
|
1
|
144491
|
my $dir = shift; |
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
|
|
18
|
my ( $new_dir, $root ); |
30
|
3
|
100
|
|
|
|
99
|
$new_dir = pushd($dir) if $dir; |
31
|
3
|
|
100
|
|
|
323
|
$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
|
|
|
|
|
206
|
try { $root = scalar git::rev_parse qw(--show-toplevel) } |
40
|
3
|
|
|
3
|
|
185
|
}; |
|
3
|
|
|
|
|
2979
|
|
41
|
3
|
100
|
|
|
|
28468
|
croak "Error in $dir: $stderr" |
42
|
|
|
|
|
|
|
if $stderr; |
43
|
|
|
|
|
|
|
|
44
|
2
|
|
|
|
|
36
|
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
|
134815
|
return git::rev_parse( '--abbrev-ref', 'HEAD' ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub https_remote_url { |
54
|
2
|
|
|
2
|
1
|
10
|
my $remote_url = remote_url(shift); |
55
|
2
|
100
|
|
|
|
53
|
return undef unless $remote_url; |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
4
|
my $branch = shift; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# remove trailing .git |
60
|
1
|
|
|
|
|
20
|
$remote_url =~ s{\.git\z}{}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# remove 'git@' from git@github.com:username/repo.git |
63
|
1
|
|
|
|
|
15
|
$remote_url =~ s{\w*\@}{}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# remove : from git@github.com:username/repo.git |
66
|
1
|
|
|
|
|
29
|
$remote_url =~ s{(\w):(\w)}{$1/$2}; |
67
|
|
|
|
|
|
|
|
68
|
1
|
50
|
|
|
|
6
|
if ($branch) { |
69
|
0
|
|
|
|
|
0
|
$remote_url .= '/tree/' . current_branch_name(); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
16
|
my $uri = URI->new( uf_uristr($remote_url) ); |
73
|
1
|
|
|
|
|
1908
|
$uri->scheme('https'); |
74
|
1
|
|
|
|
|
2008
|
return $uri; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub is_inside_work_tree { |
78
|
2
|
|
|
2
|
1
|
12608
|
my $success; |
79
|
|
|
|
|
|
|
capture_stderr { |
80
|
|
|
|
|
|
|
try { |
81
|
2
|
|
|
|
|
157
|
$success = git::rev_parse('--is-inside-work-tree'); |
82
|
2
|
|
|
2
|
|
3578
|
}; |
83
|
2
|
|
|
|
|
104
|
}; |
84
|
2
|
|
|
|
|
18494
|
return $success; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub ignored_files { |
88
|
5
|
|
100
|
5
|
1
|
3970
|
my $dir = shift || '.'; |
89
|
5
|
|
|
|
|
22
|
my @success; |
90
|
|
|
|
|
|
|
my $stderr = capture_stderr { |
91
|
|
|
|
|
|
|
try { |
92
|
5
|
|
|
|
|
334
|
@success = git::ls_files( |
93
|
|
|
|
|
|
|
$dir, '--ignored', '--exclude-standard', |
94
|
|
|
|
|
|
|
'--others' |
95
|
|
|
|
|
|
|
); |
96
|
5
|
|
|
5
|
|
4817
|
}; |
97
|
5
|
|
|
|
|
196
|
}; |
98
|
|
|
|
|
|
|
|
99
|
5
|
100
|
|
|
|
50420
|
croak "Cannot find ignored files in dir: $stderr" if $stderr; |
100
|
|
|
|
|
|
|
|
101
|
4
|
|
50
|
|
|
187
|
return \@success || []; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub remote_url { |
105
|
3
|
|
50
|
3
|
1
|
34663
|
my $remote = shift || 'origin'; |
106
|
3
|
|
|
|
|
37
|
my $url; |
107
|
|
|
|
|
|
|
my $stderr = capture_stderr { |
108
|
|
|
|
|
|
|
try { |
109
|
3
|
|
|
|
|
353
|
$url = git::remote( 'get-url', $remote ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
catch { |
113
|
|
|
|
|
|
|
try { |
114
|
1
|
|
|
|
|
56
|
$url = git::config( '--get', "remote.$remote.url" ); |
115
|
1
|
|
|
|
|
9020
|
}; |
116
|
|
|
|
|
|
|
} |
117
|
3
|
|
|
3
|
|
130
|
}; |
|
3
|
|
|
|
|
2911
|
|
118
|
|
|
|
|
|
|
|
119
|
3
|
|
|
|
|
32339
|
return $url; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#ABSTRACT: Shortcuts for common Git commands |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |