line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
48628
|
use strict; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
36
|
|
2
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
81
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Git::Helpers; |
5
|
|
|
|
|
|
|
our $VERSION = '0.000021'; |
6
|
1
|
|
|
1
|
|
7
|
use Carp qw( croak ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
7
|
1
|
|
|
1
|
|
7
|
use Capture::Tiny 'capture_stderr'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
55
|
|
8
|
1
|
|
|
1
|
|
527
|
use File::pushd qw( pushd ); |
|
1
|
|
|
|
|
1358
|
|
|
1
|
|
|
|
|
80
|
|
9
|
1
|
|
|
1
|
|
526
|
use Git::Sub; |
|
1
|
|
|
|
|
44957
|
|
|
1
|
|
|
|
|
10
|
|
10
|
1
|
|
|
|
|
14
|
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
|
|
|
|
|
|
|
'travis_url', |
19
|
|
|
|
|
|
|
] |
20
|
1
|
|
|
1
|
|
674
|
}; |
|
1
|
|
|
|
|
12314
|
|
21
|
1
|
|
|
1
|
|
1301
|
use Try::Tiny qw( catch try ); |
|
1
|
|
|
|
|
1582
|
|
|
1
|
|
|
|
|
68
|
|
22
|
1
|
|
|
1
|
|
724
|
use URI (); |
|
1
|
|
|
|
|
5055
|
|
|
1
|
|
|
|
|
38
|
|
23
|
1
|
|
|
1
|
|
669
|
use URI::FromHash qw( uri ); |
|
1
|
|
|
|
|
9223
|
|
|
1
|
|
|
|
|
85
|
|
24
|
1
|
|
|
1
|
|
612
|
use URI::Heuristic qw(uf_uristr); |
|
1
|
|
|
|
|
1961
|
|
|
1
|
|
|
|
|
83
|
|
25
|
1
|
|
|
1
|
|
561
|
use URI::git (); |
|
1
|
|
|
|
|
9141
|
|
|
1
|
|
|
|
|
695
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub checkout_root { |
28
|
3
|
|
|
3
|
1
|
113296
|
my $dir = shift; |
29
|
|
|
|
|
|
|
|
30
|
3
|
|
|
|
|
24
|
my ( $new_dir, $root ); |
31
|
3
|
100
|
|
|
|
54
|
$new_dir = pushd($dir) if $dir; |
32
|
3
|
|
100
|
|
|
343
|
$dir ||= '.'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# the exception thrown by rev-parse when we're not in a repo is not |
35
|
|
|
|
|
|
|
# very helpful (see following), so just ditch it in favor of the error |
36
|
|
|
|
|
|
|
# output. |
37
|
|
|
|
|
|
|
# "rev_parse error 128 at /home/maxmind/perl5/lib/perl5/Git/Helpers.pm line 30" |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $stderr = capture_stderr { |
40
|
3
|
|
|
|
|
213
|
try { $root = scalar git::rev_parse qw(--show-toplevel) } |
41
|
3
|
|
|
3
|
|
211
|
}; |
|
3
|
|
|
|
|
3515
|
|
42
|
3
|
100
|
|
|
|
35861
|
croak "Error in $dir: $stderr" |
43
|
|
|
|
|
|
|
if $stderr; |
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
49
|
return $root; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Works as of 1.6.3:1 |
49
|
|
|
|
|
|
|
# http://stackoverflow.com/questions/1417957/show-just-the-current-branch-in-git |
50
|
|
|
|
|
|
|
sub current_branch_name { |
51
|
1
|
|
|
1
|
1
|
150124
|
return git::rev_parse( '--abbrev-ref', 'HEAD' ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub https_remote_url { |
55
|
3
|
|
|
3
|
1
|
14
|
my $remote_url = remote_url(shift); |
56
|
3
|
100
|
|
|
|
53
|
return undef unless $remote_url; |
57
|
|
|
|
|
|
|
|
58
|
2
|
|
|
|
|
11
|
my $branch = shift; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# remove trailing .git |
61
|
2
|
|
|
|
|
40
|
$remote_url =~ s{\.git\z}{}; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# remove 'git@' from git@github.com:username/repo.git |
64
|
2
|
|
|
|
|
27
|
$remote_url =~ s{\w*\@}{}; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# remove : from git@github.com:username/repo.git |
67
|
2
|
|
|
|
|
60
|
$remote_url =~ s{(\w):(\w)}{$1/$2}; |
68
|
|
|
|
|
|
|
|
69
|
2
|
50
|
|
|
|
9
|
if ($branch) { |
70
|
0
|
|
|
|
|
0
|
$remote_url .= '/tree/' . current_branch_name(); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
29
|
my $uri = URI->new( uf_uristr($remote_url) ); |
74
|
2
|
|
|
|
|
2367
|
$uri->scheme('https'); |
75
|
2
|
|
|
|
|
1279
|
return $uri; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub is_inside_work_tree { |
79
|
2
|
|
|
2
|
1
|
15450
|
my $success; |
80
|
|
|
|
|
|
|
capture_stderr { |
81
|
|
|
|
|
|
|
try { |
82
|
2
|
|
|
|
|
162
|
$success = git::rev_parse('--is-inside-work-tree'); |
83
|
2
|
|
|
2
|
|
2702
|
}; |
84
|
2
|
|
|
|
|
104
|
}; |
85
|
2
|
|
|
|
|
25582
|
return $success; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub ignored_files { |
89
|
5
|
|
100
|
5
|
1
|
4978
|
my $dir = shift || '.'; |
90
|
5
|
|
|
|
|
22
|
my @success; |
91
|
|
|
|
|
|
|
my $stderr = capture_stderr { |
92
|
|
|
|
|
|
|
try { |
93
|
5
|
|
|
|
|
374
|
@success = git::ls_files( |
94
|
|
|
|
|
|
|
$dir, '--ignored', '--exclude-standard', |
95
|
|
|
|
|
|
|
'--others' |
96
|
|
|
|
|
|
|
); |
97
|
5
|
|
|
5
|
|
6412
|
}; |
98
|
5
|
|
|
|
|
280
|
}; |
99
|
|
|
|
|
|
|
|
100
|
5
|
100
|
|
|
|
66685
|
croak "Cannot find ignored files in dir: $stderr" if $stderr; |
101
|
|
|
|
|
|
|
|
102
|
4
|
|
50
|
|
|
199
|
return \@success || []; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub remote_url { |
106
|
4
|
|
50
|
4
|
1
|
36955
|
my $remote = shift || 'origin'; |
107
|
4
|
|
|
|
|
13
|
my $url; |
108
|
|
|
|
|
|
|
my $stderr = capture_stderr { |
109
|
|
|
|
|
|
|
try { |
110
|
4
|
|
|
|
|
399
|
$url = git::remote( 'get-url', $remote ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
catch { |
114
|
|
|
|
|
|
|
try { |
115
|
1
|
|
|
|
|
60
|
$url = git::config( '--get', "remote.$remote.url" ); |
116
|
1
|
|
|
|
|
11405
|
}; |
117
|
|
|
|
|
|
|
} |
118
|
4
|
|
|
4
|
|
155
|
}; |
|
4
|
|
|
|
|
4304
|
|
119
|
|
|
|
|
|
|
|
120
|
4
|
|
|
|
|
39309
|
return $url; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub travis_url { |
124
|
1
|
|
|
1
|
1
|
10
|
my $remote_url = https_remote_url(shift); |
125
|
1
|
|
|
|
|
12
|
my $url = URI->new($remote_url); |
126
|
1
|
|
|
|
|
122
|
return uri( |
127
|
|
|
|
|
|
|
scheme => 'https', |
128
|
|
|
|
|
|
|
host => 'travis-ci.org', |
129
|
|
|
|
|
|
|
path => $url->path, |
130
|
|
|
|
|
|
|
); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
#ABSTRACT: Shortcuts for common Git commands |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
__END__ |