bin/gitcrypt

filter: Statementstmt 74.7% 154 / 206 Branchbran 61.4% 59 / 96 Conditioncond 48.1% 26 / 54 MC/DCmcdc 26.9% 7 / 26 Subroutinesub 91.1% 31 / 34 Podpod n/a totaltotal 66.5% 277 / 416 CC 61 SCAR 19.7
CC
61
Cov
67%
precommit
42.0
set_key
8.6
validate
8.1
CRAP 7.2
↑ Summary blib/lib/Git/Crypt.pm »
1 #!/usr/bin/env perl
2 35 ▶use Git::Crypt;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 35 ▶use Crypt::CBC;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 35 ▶use IO::All;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 35 ▶use Proc::ProcessTable;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub pid_args {
11 8 ▶ my $t = new Proc::ProcessTable;
Subroutine pid_args: called CC=3 SCAR=11.0
12 8 foreach my $p ( @{$t->table} ) {
13 82 ▶ return $p->cmndline
Branch: 1 branch
BranchTrueFalseTotal
if $p->pid == $$ 8 74 82
14 if ( $p->pid == $$ )
15 ;
16 }
17 }
18  
19  
20 #Command line gitcrypt utility. This tool should be used inside gitdir containing .gitcrypt config file
21  
22 35 ▶my $config_file = $ENV{GITCRYPT_CONFIG_FILE} || '.gitcrypt';
Condition50%1/2
$ENV{'GITCRYPT_CONFIG_FILE'} || '.gitcrypt'
l!l
350
MC/DC0%0/1
$ENV{'GITCRYPT_CONFIG_FILE'} || '.gitcrypt'
$ENV{'GITCRYPT_CONFIG_FILE'}
Truth table50%1/2
A
A= $ENV{'GITCRYPT_CONFIG_FILE'}
Aresult
11
00
23  
24 #load config or start with new one
25 sub get_config {
26 74 ▶ ( -e $config_file )
Subroutine get_config: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
-e $config_file ? : 70 4 74
27 ? decode_json io($config_file)->slurp
28 : { files => [] };
29 }
30 35 my $config = get_config();
31  
32 sub new_gitcrypt {
33 39 ▶ my $config = shift;
Subroutine new_gitcrypt: called CC=7 SCAR=19.5
34 Git::Crypt->new(
35 files => $config->{ files },
36 key => $config->{ key },
37 cipher_name => $config->{ cipher_name }||undef,
38 salt => (exists $config->{salt} and defined $config->{salt})
39 ? pack( "H16", $config->{ salt } )
40 : undef
41 ,
42 key => $config->{ key }||undef,
43 cipher_name => $config->{ cipher_name }||undef,
44 salt => $config->{ salt }||undef,
45 39 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
exists $config->{'salt'} && defined $config->{'salt'} ? : 29 10 39
Condition100%11/11
$config->{'cipher_name'} || undef
l!l
354
exists $config->{"salt"} and defined $config->{"salt"}
!ll&&!rl&&r
2829
$config->{'key'} || undef
l!l
336
$config->{'cipher_name'} || undef
l!l
354
$config->{'salt'} || undef
l!l
2910
MC/DC100%1/1
$config->{'cipher_name'} || undef
$config->{'cipher_name'}
MC/DC100%2/2
exists $config->{"salt"} and defined $config->{"salt"}
exists $config->{"salt"} defined $config->{"salt"}
MC/DC100%1/1
$config->{'key'} || undef
$config->{'key'}
MC/DC100%1/1
$config->{'cipher_name'} || undef
$config->{'cipher_name'}
MC/DC100%1/1
$config->{'salt'} || undef
$config->{'salt'}
Truth table100%2/2
A
A= $config->{'cipher_name'}
Aresult
11
00
Truth table100%3/3
A and B
A= exists $config->{"salt"}B= defined $config->{"salt"}
ABresult
0X0
100
111
Truth table100%2/2
A
A= $config->{'key'}
Aresult
11
00
Truth table100%2/2
A
A= $config->{'cipher_name'}
Aresult
11
00
Truth table100%2/2
A
A= $config->{'salt'}
Aresult
11
00
46 }
47  
48 35 my $gitcrypt = new_gitcrypt( get_config() );
49  
50 #get current action
51 35 ▶my $action = $ARGV[0]||undef;
Condition50%1/2
$ARGV[0] || undef
l!l
350
MC/DC0%0/1
$ARGV[0] || undef
$ARGV[0]
Truth table50%1/2
A
A= $ARGV[0]
Aresult
11
00
52 35 ▶ if (!@ARGV) { show_commands(); }
Branch: 12 branches
BranchTrueFalseTotal
if (not @ARGV) { } 0 35 35
elsif ($action eq 'init') { } 2 33 35
elsif ($action eq 'set') { } 6 27 33
elsif ($action eq 'change') { } 2 25 27
elsif ($action eq 'list') { } 2 23 25
elsif ($action eq 'add') { } 4 19 23
elsif ($action eq 'del') { } 2 17 19
elsif ($action eq 'encrypt') { } 10 7 17
elsif ($action eq 'decrypt') { } 3 4 7
elsif ($action eq 'status') { } 4 0 4
elsif ($action eq 'help') { } 0 0 0
elsif ($action eq 'precommit') { } 0 0 0
53 2 elsif ( $action eq 'init' ) { init() }
54 6 elsif ( $action eq 'set' ) { set() }
55 2 elsif ( $action eq 'change' ) { change() }
56 2 elsif ( $action eq 'list' ) { list() }
57 4 elsif ( $action eq 'add' ) { add() }
58 2 elsif ( $action eq 'del' ) { del() }
59 10 elsif ( $action eq 'encrypt' ) { encrypt() }
60 3 elsif ( $action eq 'decrypt' ) { decrypt() }
61 4 elsif ( $action eq 'status' ) { status() }
62 0 elsif ( $action eq 'help' ) { show_commands() }
63 0 elsif ( $action eq 'precommit' ) { precommit() }
64 0 else { print "Command not avaliable\n"; }
65  
66 sub show_commands {
67 0 ▶ print <<COMMANDS;
Subroutine show_commands: not called CC=1 SCAR=6.9
68 Avaliable commands:
69 gitcrypt init
70  
71 Configuration options:
72 gitcrypt set cipher Blowfish
73 gitcrypt set key "some key"
74 gitcrypt set salt "some salt"
75  
76 Key and salt changes:
77 gitcrypt set key "some key"
78 gitcrypt set salt "some salt"
79  
80 Managing files:
81 gitcrypt list
82 gitcrypt add some/file1 other/file
83 gitcrypt del some/file1 file2
84  
85 Encrypt files:
86 gitcrypt encrypt
87 gitcrypt encrypt file1 file2
88  
89 Decrypt files:
90 gitcrypt decrypt
91 gitcrypt decrypt file1 file2
92  
93 Precommit:
94 gitcrypt precommit
95 COMMANDS
96 }
97  
98 sub status {
99 4 ▶ print "cipher ".$gitcrypt->cipher_name,"\n"
Subroutine status: called CC=4 SCAR=14.9
Branch: 1 branch
BranchTrueFalseTotal
if defined $gitcrypt->cipher_name 4 0 4
100 if defined $gitcrypt->cipher_name;
101 4 ▶ print "key ".$gitcrypt->key,"\n"
Branch: 1 branch
BranchTrueFalseTotal
if defined $gitcrypt->key 4 0 4
102 if defined $gitcrypt->key;
103 4 ▶ print "salt ".$gitcrypt->salt,"\n"
Branch: 1 branch
BranchTrueFalseTotal
if defined $gitcrypt->salt 4 0 4
104 if defined $gitcrypt->salt;
105 4 list();
106 }
107  
108 sub init {
109 2 ▶ if ( ! -e $config_file ) {
Subroutine init: called CC=2 SCAR=7.4
Branch: 1 branch
BranchTrueFalseTotal
if (not -e $config_file) { } 2 0 2
110 2 print "Initializing $config_file";
111 2 print <<STEPS;
112 Now configure your cipher, key and salt:
113 gitcrypt set cipher Blowfish
114 gitcrypt set key some key
115 gitcrypt set salt some salt
116  
117 STEPS
118 2 save_config();
119 } else {
120 0 print "You already initialized an $config_file\n";
121 }
122 }
123  
124 sub precommit {
125 0 ▶ return 0 if ! validate();
Subroutine precommit: not called CC=6 SCAR=37.4
Branch: 1 branch
BranchTrueFalseTotal
unless validate() 0 0 0
126 0 my @decrypted_files = @{ decrypted_files() };
127 0 $gitcrypt->encrypt;
128 0 print "Encrypted.\n";sleep 4;
129 0 for ( @{ $gitcrypt->files } ) {
130 0 ▶ if ( -e $_->{ file } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $_->{'file'}) { } 0 0 0
131 0 my $file = $_->{ file };
132 0 `git add $file`;
133 } else {
134 0 print "File missing: ". $_->{ file }."\n";
135 }
136 }
137 0 for ( @decrypted_files ) {
138 0 ▶ if ( -e $_->{ file } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $_->{"file"}) 0 0 0
139 0 $gitcrypt->decrypt( $_->{ file } );
140 }
141 }
142 0 save_config();
143 0 return 1;
144 }
145  
146 sub validate {
147 15 ▶ return 1
Subroutine validate: called CC=4 SCAR=20.9
Branch: 1 branch
BranchTrueFalseTotal
if defined $gitcrypt->cipher_name and defined $gitcrypt->salt and defined $gitcrypt->key 15 0 15
Condition33%2/6
defined $gitcrypt->cipher_name and defined $gitcrypt->salt and defined $gitcrypt->key
!ll&&!rl&&r
0015
defined $gitcrypt->cipher_name and defined $gitcrypt->salt
!ll&&!rl&&r
0015
MC/DC0%0/3
defined $gitcrypt->cipher_name and defined $gitcrypt->salt and defined $gitcrypt->key
defined $gitcrypt->cipher_name defined $gitcrypt->salt defined $gitcrypt->key
Truth table25%1/4
A and B and C
A= defined $gitcrypt->cipher_nameB= defined $gitcrypt->saltC= defined $gitcrypt->key
ABCresult
0XX0
10X0
1100
1111
148 if defined $gitcrypt->cipher_name
149 and defined $gitcrypt->salt
150 and defined $gitcrypt->key
151 ;
152 0 print <<HELP;
153 You must set the cipher, salt and key.
154 Use gitcrypt status and see current configuration.
155 HELP
156 0 return 0;
157 }
158  
159 sub encrypt {
160 10 ▶ return 0 if ! validate();
Subroutine encrypt: called CC=5 SCAR=19.6
Branch: 1 branch
BranchTrueFalseTotal
unless validate() 0 10 10
161 10 ▶ if ( $action eq 'encrypt' and scalar @ARGV > 1 ) { #contain 1 or more file paths
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq 'encrypt' and scalar @ARGV > 1) { } 0 10 10
Condition33%1/3
$action eq "encrypt" and scalar @ARGV > 1
!ll&&!rl&&r
0100
MC/DC0%0/2
$action eq "encrypt" and scalar @ARGV > 1
$action eq "encrypt" scalar @ARGV > 1
Truth table33%1/3
A and B
A= $action eq "encrypt"B= scalar @ARGV > 1
ABresult
0X0
100
111
162 0 shift @ARGV; #remove action
163 0 for ( @ARGV ) {
164 0 $gitcrypt->encrypt( $_ );
165 }
166 } else {
167 10 $gitcrypt->encrypt;
168 }
169 10 save_config();
170 10 print "Encrypted.";
171 10 return 1;
172 }
173  
174 sub decrypt {
175 5 ▶ return 0 if ! validate();
Subroutine decrypt: called CC=5 SCAR=18.4
Branch: 1 branch
BranchTrueFalseTotal
unless validate() 0 5 5
176 5 ▶ if ( $action eq 'decrypt' and scalar @ARGV > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq 'decrypt' and scalar @ARGV > 1) { } 0 5 5
Condition66%2/3
$action eq "decrypt" and scalar @ARGV > 1
!ll&&!rl&&r
230
MC/DC0%0/2
$action eq "decrypt" and scalar @ARGV > 1
$action eq "decrypt" scalar @ARGV > 1
Truth table66%2/3
A and B
A= $action eq "decrypt"B= scalar @ARGV > 1
ABresult
0X0
100
111
177 0 shift @ARGV;
178 0 for ( @ARGV ) {
179 0 $gitcrypt->decrypt( $_ );
180 }
181 } else {
182 5 $gitcrypt->decrypt;
183 }
184 5 save_config();
185 5 print "Decrypted.\n";
186 5 return 1;
187 }
188  
189 sub del {
190 2 ▶ if ( ! $ARGV[1] ) {
Subroutine del: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
if (not $ARGV[1]) { } 0 2 2
191 0 print <<HELP;
192 You must supply one or more files to be deleted.
193 ie: gitcrypt del file1 dir/file2
194 HELP
195 } else {
196 2 shift @ARGV;
197 2 print "Deleting files:\n";
198 2 $gitcrypt->del( \@ARGV );
199 2 save_config();
200 }
201 }
202  
203 sub add {
204 4 ▶ if ( ! $ARGV[1] ) {
Subroutine add: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
if (not $ARGV[1]) { } 0 4 4
205 0 print <<HELP;
206 You must supply one or more files to be added.
207 ie: gitcrypt add file1 dir/file2\n";
208 HELP
209 } else {
210 4 shift @ARGV;
211 4 print "Adding files: \n";
212 4 $gitcrypt->add( \@ARGV );
213 4 save_config();
214 }
215 }
216  
217 sub list {
218 #print files from $config
219 6 ▶ if ( ! $config->{ files } || scalar @{ $config->{ files } } == 0 ) {
Subroutine list: called CC=5 SCAR=16.1
Branch: 1 branch
BranchTrueFalseTotal
if (not $config->{"files"} or scalar @{$config->{"files"};} == 0) 2 4 6
Condition66%2/3
not $config->{"files"} or scalar @{$config->{"files"};} == 0
l!l&&r!l&&!r
024
MC/DC50%1/2
not $config->{"files"} or scalar @{$config->{"files"};} == 0
not $config->{"files"} scalar @{$config->{"files"};} == 0
Truth table66%2/3
not(A) or B
A= not $config->{"files"}B= scalar @{$config->{"files"};} == 0
ABresult
1X1
011
000
220 2 print "No files added\n";
221 2 return;
222 }
223 4 print "Files added:\n";
224 4 print "Status: File:\n";
225 4 for ( @{ $gitcrypt->files } ) {
226 my $is_crypted = $_->{is_encrypted}
227 12 ▶ ? "encrypted "
Branch: 1 branch
BranchTrueFalseTotal
$_->{'is_encrypted'} ? : 6 6 12
228 : "decrypted "
229 ;
230 12 print $is_crypted , $_->{file} , "\n";
231 }
232 }
233  
234 sub set {
235 6 ▶ if ( $ARGV[1] eq 'cipher' ) {
Subroutine set: called CC=4 SCAR=14.1
Branch: 3 branches
BranchTrueFalseTotal
if ($ARGV[1] eq 'cipher') { } 2 4 6
elsif ($ARGV[1] eq 'key') { } 2 2 4
elsif ($ARGV[1] eq 'salt') { } 2 0 2
236 2 set_cipher();
237 } elsif ( $ARGV[1] eq 'key' ) {
238 2 set_key();
239 } elsif ( $ARGV[1] eq 'salt' ) {
240 2 set_salt();
241 } else {
242 0 print "incorrect option $ARGV[1]\n";
243 }
244 }
245  
246 sub change {
247 2 ▶ if ( $ARGV[1] eq 'key' ) {
Subroutine change: called CC=3 SCAR=11.4
Branch: 2 branches
BranchTrueFalseTotal
if ($ARGV[1] eq 'key') { } 1 1 2
elsif ($ARGV[1] eq 'salt') { } 1 0 1
248 1 change_key();
249 } elsif ( $ARGV[1] eq 'salt' ) {
250 1 change_salt();
251 } else {
252 0 print "incorrect option $ARGV[1]\n";
253 }
254 }
255  
256 sub capture_cli_args {
257 8 ▶ my $discard_string = shift;
Subroutine capture_cli_args: called CC=1 SCAR=0.0
258 8 my $cliargs = pid_args() ;
259 8 $cliargs =~ s|^COMMAND\n||gm;
260 8 $cliargs =~ s|^.+$discard_string( +)||gm;
261 8 $cliargs =~ s|\n$||;
262 8 $cliargs;
263 }
264  
265 sub set_cipher {
266 #set cipher
267 2 ▶ if ( ! $ARGV[2] ) {
Subroutine set_cipher: called CC=5 SCAR=19.9
Branch: 1 branch
BranchTrueFalseTotal
unless ($ARGV[2]) 0 2 2
268 0 print "You must set a cipher. ie: Blowfish \n";
269 0 return;
270 }
271 2 shift @ARGV; #set
272 2 shift @ARGV; #cipher
273 2 my $cipher = capture_cli_args( 'set cipher' );
274 2 ▶ print "You cannot change the cipher. Its already set to: ",$gitcrypt->cipher_name,"\n"
Branch: 1 branch
BranchTrueFalseTotal
if $gitcrypt->cipher_name and $gitcrypt->cipher_name ne "" 0 2 2
Condition25%2/8
$gitcrypt->cipher_name && $gitcrypt->cipher_name ne '' && (print('You cannot change the cipher. Its already set to: ', $gitcrypt->cipher_name, "\n") && (return))
!ll&&!rl&&r
200
$gitcrypt->cipher_name and $gitcrypt->cipher_name ne ""
!ll&&!rl&&r
200
print "You cannot change the cipher. Its already set to: ", $gitcrypt->cipher_name, "\n" and return
!ll
00
MC/DC0%0/3
$gitcrypt->cipher_name && $gitcrypt->cipher_name ne '' && (print('You cannot change the cipher. Its already set to: ', $gitcrypt->cipher_name, "\n") && (return))
$gitcrypt->cipher_name $gitcrypt->cipher_name ne "" print "You cannot change the cipher. Its already set to: ", $gitcrypt->cipher_name, "\n"
Truth table25%1/4
A and B && C
A= $gitcrypt->cipher_nameB= $gitcrypt->cipher_name ne ""C= print "You cannot change the cipher. Its already set to: ", $gitcrypt->cipher_name, "\n"
ABCresult
0XX0
10X0
1100
1111
275 and return
276 if $gitcrypt->cipher_name and $gitcrypt->cipher_name ne '';
277 2 $gitcrypt->cipher_name( $cipher );
278 2 print "Set cipher to: '",$gitcrypt->cipher_name,"\n";
279 2 save_config();
280 }
281  
282 sub reload_gitcrypt {
283 4 ▶ $gitcrypt = new_gitcrypt( get_config() );
Subroutine reload_gitcrypt: called CC=1 SCAR=0.0
284 }
285  
286 sub encrypted_files {
287 2 ▶ my @encrypted_files = map { $_->{ is_encrypted } ? $_ : () } @{ $gitcrypt->files };
Subroutine encrypted_files: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_->{'is_encrypted'} ? : 3 3 6
288 2 return \@encrypted_files;
289 }
290  
291 sub decrypted_files {
292 0 ▶ my @decrypted_files = map { !$_->{ is_encrypted } ? $_ : () } @{ $gitcrypt->files };
Subroutine decrypted_files: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
!$_->{'is_encrypted'} ? : 0 0 0
293 0 return \@decrypted_files;
294 }
295  
296 sub change_salt {
297 1 ▶ if ( ! $ARGV[2] ) {
Subroutine change_salt: called CC=4 SCAR=15.2
Branch: 1 branch
BranchTrueFalseTotal
unless ($ARGV[2]) 0 1 1
298 0 print "You did not pass a salt\n";
299 return
300 0 }
301 1 my @files = @{$gitcrypt->files};
302 1 my @encrypted_files = @{ encrypted_files() };
303 1 ▶ if ( decrypt() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (decrypt()) { } 1 0 1
304 1 print "Files decrypted. Will change salt.\n";
305 1 save_salt( capture_cli_args( 'change salt' ) );
306 1 for ( @encrypted_files ) {
307 0 $gitcrypt->encrypt( $_->{file} );
308 }
309 } else {
310 0 print "Salt not changed.\n";
311 }
312 1 save_config();
313 }
314  
315 sub save_salt {
316 1 ▶ my $salt = shift;
Subroutine save_salt: called CC=1 SCAR=0.0
317 1 $gitcrypt->salt( $salt );
318 1 print "Set salt to: '",$gitcrypt->salt,"\n";
319 1 save_config();
320 1 reload_gitcrypt();
321 }
322  
323 sub change_key {
324 #decrypt encrypted files
325 #change encryption key
326 #encrypt files that were encrypted previously
327 1 ▶ if ( ! $ARGV[2] ) {
Subroutine change_key: called CC=4 SCAR=14.7
Branch: 1 branch
BranchTrueFalseTotal
unless ($ARGV[2]) 0 1 1
328 0 print "You did not pass a key\n";
329 return
330 0 }
331 1 my @files = @{$gitcrypt->files};
332 1 my @encrypted_files = @{ encrypted_files() };
333 1 ▶ if ( decrypt() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (decrypt()) { } 1 0 1
334 1 print "Files decrypted. Will change key.\n";
335 1 save_key( capture_cli_args( 'change key' ) );
336 1 for ( @encrypted_files ) {
337 3 $gitcrypt->encrypt( $_->{file} );
338 }
339 } else {
340 0 print "Key not changed.\n";
341 }
342 1 save_config();
343 }
344  
345 sub save_key {
346 3 ▶ my $key = shift;
Subroutine save_key: called CC=1 SCAR=0.0
347 3 $gitcrypt->key( $key );
348 3 print "Set key to: '",$gitcrypt->key,"\n";
349 3 save_config();
350 3 reload_gitcrypt();
351 }
352  
353 sub set_key {
354 #set key
355 2 ▶ if ( ! $ARGV[2] ) {
Subroutine set_key: called CC=5 SCAR=21.6
Branch: 1 branch
BranchTrueFalseTotal
unless ($ARGV[2]) 0 2 2
356 0 print "You did not pass a key\n";
357 return
358 0 }
359 2 shift @ARGV; #set
360 2 shift @ARGV; #key
361 2 ▶ warn "Cannot set new key. Key has already been set. Use change key <newkey> to change."
Branch: 1 branch
BranchTrueFalseTotal
if defined $gitcrypt->key and $gitcrypt->key ne "" 0 2 2
Condition25%2/8
defined $gitcrypt->key && $gitcrypt->key ne '' && (warn('Cannot set new key. Key has already been set. Use change key <newkey> to change.') && (return))
!ll&&!rl&&r
200
defined $gitcrypt->key and $gitcrypt->key ne ""
!ll&&!rl&&r
200
warn "Cannot set new key. Key has already been set. Use change key <newkey> to change." and return
!ll
00
MC/DC0%0/3
defined $gitcrypt->key && $gitcrypt->key ne '' && (warn('Cannot set new key. Key has already been set. Use change key <newkey> to change.') && (return))
defined $gitcrypt->key $gitcrypt->key ne "" warn "Cannot set new key. Key has already been set. Use change key <newkey> to change."
Truth table25%1/4
A and B && C
A= defined $gitcrypt->keyB= $gitcrypt->key ne ""C= warn "Cannot set new key. Key has already been set. Use change key <newkey> to change."
ABCresult
0XX0
10X0
1100
1111
362 and return
363 if defined $gitcrypt->key and $gitcrypt->key ne '';
364 2 save_key( capture_cli_args( 'set key' ) );
365 }
366  
367 sub set_salt {
368 #set salt
369 2 ▶ if ( ! $ARGV[2] ) {
Subroutine set_salt: called CC=5 SCAR=19.9
Branch: 1 branch
BranchTrueFalseTotal
unless ($ARGV[2]) 0 2 2
370 0 print "You did not pass a salt\n";
371 return
372 0 }
373 2 shift @ARGV; #set
374 2 shift @ARGV; #salt
375 2 my $salt = capture_cli_args( 'set salt' );
376 2 ▶ print "Cannot set new salt. Salt has already been set. Use change salt <newsalt> to change."
Branch: 1 branch
BranchTrueFalseTotal
if defined $gitcrypt->salt and $gitcrypt->salt ne "" 0 2 2
Condition25%2/8
defined $gitcrypt->salt && $gitcrypt->salt ne '' && (print('Cannot set new salt. Salt has already been set. Use change salt <newsalt> to change.') && (return))
!ll&&!rl&&r
200
defined $gitcrypt->salt and $gitcrypt->salt ne ""
!ll&&!rl&&r
200
print "Cannot set new salt. Salt has already been set. Use change salt <newsalt> to change." and return
!ll
00
MC/DC0%0/3
defined $gitcrypt->salt && $gitcrypt->salt ne '' && (print('Cannot set new salt. Salt has already been set. Use change salt <newsalt> to change.') && (return))
defined $gitcrypt->salt $gitcrypt->salt ne "" print "Cannot set new salt. Salt has already been set. Use change salt <newsalt> to change."
Truth table25%1/4
A and B && C
A= defined $gitcrypt->saltB= $gitcrypt->salt ne ""C= print "Cannot set new salt. Salt has already been set. Use change salt <newsalt> to change."
ABCresult
0XX0
10X0
1100
1111
377 and return
378 if defined $gitcrypt->salt and $gitcrypt->salt ne '';
379 2 $gitcrypt->salt( $salt );
380 2 print "Set salt to: '",$gitcrypt->salt,"\n";
381 2 save_config();
382 }
383  
384 sub save_config {
385 33 ▶ io( $config_file )->print( encode_json $gitcrypt->config );
Subroutine save_config: called CC=1 SCAR=0.0
386 }
387  
388  
↑ Summary blib/lib/Git/Crypt.pm »