bin/gitcrypt

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