| 1 | package CPAN::InGit::MutableTree; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Utility object that represents a Git Tree and pending changes | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | our $VERSION = '0.006'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Git::Raw::Index; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | has parent => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | has tree => ( is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | 11 | has branch => ( is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | 11 | has _changes => ( is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 11 | has has_changes => ( is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | 11 | has use_workdir => ( is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | 185 | ▶ | sub git_repo { shift->parent->git_repo } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
git_repo: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 93 | ▶ | sub BUILD($self, $args, @) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # branch supplied by name? look it up | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 93 | ▶ | if (defined $self->{branch} && !ref $self->{branch}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->{"branch"} and not ref $self->{"branch"}
MC/DC100%2/2
defined $self->{"branch"} and not ref $self->{"branch"}
defined $self->{"branch"}
not ref $self->{"branch"}
Truth table100%3/3
A and not(B)
A= defined $self->{"branch"}B= not ref $self->{"branch"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | my $b= Git::Raw::Branch->lookup($self->git_repo, $self->{branch}, 1) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | or croak "No local branch named '$self->{branch}'"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | $self->{branch}= $b; | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # If branch supplied and tree was not, look up the tree | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 93 | ▶ | if ($self->{branch} && !$self->{tree}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"branch"} and not $self->{"tree"}
MC/DC100%2/2
$self->{"branch"} and not $self->{"tree"}
$self->{"branch"}
not $self->{"tree"}
Truth table100%3/3
A and not(B)
A= $self->{"branch"}B= not $self->{"tree"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | $self->{tree}= $self->{branch}->peel('tree'); | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 360 | ▶ | sub get_path($self, $path) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_path: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 360 | ▶ | if ($self->has_changes) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 37 | ▶ | if (keys $self->_changes->%*) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 27 | my $node= $self->_changes; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 27 | my @path= split '/', $path; | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 27 | my $basename= pop @path; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 27 | for (@path) { | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 39 | ▶ | $node= $node->{$_} if defined $node; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 27 | ▶ | return $node->{$basename} if ref $node eq 'HASH' && $node->{$basename}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $node eq "HASH" and $node->{$basename}
MC/DC100%2/2
ref $node eq "HASH" and $node->{$basename}
ref $node eq "HASH"
$node->{$basename}
Truth table100%3/3
A and B
A= ref $node eq "HASH"B= $node->{$basename}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 31 | ▶ | if ($self->use_workdir) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 10 | my $ent= $self->git_repo->index->find($path); | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 10 | ▶ | return [ $ent->blob, $ent->mode ] | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | if $ent; | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 350 | ▶ | if ($self->tree) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 303 | ▶ | my $dirent= $self->tree->entry_bypath($path) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 286 | return [ $dirent->object, $dirent->file_mode ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 47 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 84 | ▶ | sub set_path($self, $path, $data, %opts) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_path: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # Two modes: we can be writing to the working directory and index, or be building a new tree | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # (which may or may not be connected to a branch) | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 84 | my $repo= $self->git_repo; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 84 | ▶ | my $mode= $opts{mode} // 0100644; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts{"mode"} // 33188
MC/DC100%1/1
$opts{"mode"} // 33188
$opts{"mode"}
Truth table100%2/2
A
A= $opts{"mode"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 84 | my @path= split m{/+}, $path; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 84 | my $basename= pop @path; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 84 | ▶ | if ($self->use_workdir) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 16 | my $index= $repo->index; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | 16 | my $fullpath= $self->git_repo->workdir; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | # create missing directories | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 16 | for (@path) { | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | 25 | $fullpath .= '/'.$_; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 25 | ▶ | mkdir $fullpath || die "mkdir($fullpath): $!" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$fullpath || die("mkdir($fullpath): $!")
MC/DC0%0/1
$fullpath || die("mkdir($fullpath): $!")
$fullpath
Truth table50%1/2
A
A= $fullpath
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | unless -d $fullpath; | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 16 | $fullpath .= '/'.$basename; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 16 | ▶ | if (!defined $data) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | unlink($fullpath); | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | $index->remove($path); | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # a shame there's no way to add the blob directly... | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 15 | ▶ | $data= \$data->content if ref($data)->isa('Git::Raw::Blob'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # Write file | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 15 | _mkfile($fullpath, $data, $mode); | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | # Add to the index | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 15 | $index->add_frombuffer($path, $data, $mode); | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Index mutations are in memory until written. Persist them even when the | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # caller leaves committing to the user (as cpangit-add does on HEAD). | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 16 | $index->write; | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 68 | ▶ | my $node= ($self->{_changes} //= {}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"_changes"} //= {}
MC/DC100%1/1
$self->{"_changes"} //= {}
$self->{"_changes"}
Truth table100%2/2
A
A= $self->{"_changes"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 68 | for (@path) { | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 105 | ▶ | $node= ($node->{$_} //= {}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$node->{$_} //= {}
MC/DC100%1/1
$node->{$_} //= {}
$node->{$_}
Truth table100%2/2
A
A= $node->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 105 | ▶ | ref $node eq 'HASH' or die "Can't set '$path'; '$_' is not a directory"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # Content may either be a Blob object or a scalar-ref of bytes | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 68 | ▶ | if (ref $data eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 65 | $data= Git::Raw::Blob->create($repo, $$data); | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 68 | ▶ | $node->{$basename}= defined $data? [ $data, $mode ] : undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 84 | $self->has_changes(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | 84 | ▶ | $self->{_changes} //= {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"_changes"} //= {}
MC/DC100%1/1
$self->{"_changes"} //= {}
$self->{"_changes"}
Truth table100%2/2
A
A= $self->{"_changes"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 84 | $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 15 | ▶ | sub _mkfile($path, $scalarref, $mode) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mkfile: called CC=7 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 15 | ▶ | open my $fh, '>', $path or die "open($path): $!"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 15 | ▶ | $fh->print($$scalarref) or die "write($path): $!"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 15 | ▶ | $fh->close or die "close($path): $!"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 15 | ▶ | chmod($path, $mode) || die "chmod($path, $mode): $!" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%2/8
defined $mode && $mode != 33188 && (chmod($path, $mode) || die("chmod($path, $mode): $!"))
defined $mode and $mode != 33188
chmod $path, $mode or die "chmod($path, $mode): $!"
MC/DC0%0/3
defined $mode && $mode != 33188 && (chmod($path, $mode) || die("chmod($path, $mode): $!"))
defined $mode
$mode != 33188
chmod $path, $mode
Truth table25%1/4
A and B && C
A= defined $modeB= $mode != 33188C= chmod $path, $mode
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | if defined $mode && $mode != 0100644; | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 36 | ▶ | sub update_tree($self) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_tree: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # If using the Index, the index can write the new tree | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 36 | ▶ | if ($self->use_workdir) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 5 | $self->tree($self->git_repo->index->write_tree); | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 31 | $self->tree(_assemble_tree($self->git_repo, $self->tree, $self->_changes)); | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | 31 | $self->_changes({}); # reset the changes hash | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # don't reset has_changes until it has been committed | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # merge a hashref of changes into the previous Tree, and return the new Tree | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # Changes look like: | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # { | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # "path1" => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # "filename" => [ $blob, $mode ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # "fname2" => [ $blob, $mode ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # } | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # } | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 102 | ▶ | sub _assemble_tree($repo, $tree, $changes) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assemble_tree: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 102 | ▶ | my $treebuilder= Git::Raw::Tree::Builder->new($repo, ($tree? ($tree) : ())); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 102 | for my $name (keys %$changes) { | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 134 | my $ent= $changes->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | 134 | ▶ | if (!defined $ent) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $treebuilder->remove($name); | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 134 | ▶ | if (ref $ent eq 'HASH') { # a subdirectory | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 71 | my $dirent= $treebuilder->get($name); | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 71 | ▶ | my $subdir= $dirent && $dirent->type == Git::Raw::Object::TREE() | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$dirent and $dirent->type == Git::Raw::Object::TREE()
MC/DC50%1/2
$dirent and $dirent->type == Git::Raw::Object::TREE()
$dirent
$dirent->type == Git::Raw::Object::TREE()
Truth table66%2/3
A and B
A= $direntB= $dirent->type == Git::Raw::Object::TREE()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | ? Git::Raw::Tree->lookup($repo, $dirent->id) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 71 | $ent= [ _assemble_tree($repo, $subdir, $ent), 0040000 ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 134 | $treebuilder->insert($name, @$ent); | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 102 | return $treebuilder->write; # returns Git::Raw::Tree | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 34 | ▶ | sub commit($self, $message, %opts) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
commit: called CC=15 SCAR=28.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 34 | ▶ | croak "No changes added" unless $self->has_changes; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 34 | my $repo= $self->git_repo; | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | 34 | $self->update_tree; | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | 34 | my $branch= $self->branch; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | 34 | my $cur_sig= $self->parent->new_signature; | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | 34 | ▶ | my $author= $opts{author} // $cur_sig; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts{"author"} // $cur_sig
MC/DC0%0/2
$opts{"author"} // $cur_sig
$opts{"author"}
$cur_sig
Truth table33%1/3
A // B
A= $opts{"author"}B= $cur_sig
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 34 | ▶ | my $update_head= $self->use_workdir // $opts{update_head}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->use_workdir // $opts{"update_head"}
MC/DC50%1/2
$self->use_workdir // $opts{"update_head"}
$self->use_workdir
$opts{"update_head"}
Truth table66%2/3
A // B
A= $self->use_workdirB= $opts{"update_head"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 34 | ▶ | my $committer= $opts{committer} // $cur_sig; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts{"committer"} // $cur_sig
MC/DC0%0/2
$opts{"committer"} // $cur_sig
$opts{"committer"}
$cur_sig
Truth table33%1/3
A // B
A= $opts{"committer"}B= $cur_sig
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | my $parents= $self->use_workdir? ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # dies on new repo if HEAD doesn't exist yet, in which case no parents | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | ▶ | eval { [ $self->git_repo->head->target ] } || [] | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | : $branch? [ $self->branch->peel('commit') ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 34 | ▶ | : length $opts{create_branch}? [] # fresh branch, no parent commit | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
eval {
do {
[$self->git_repo->head->target]
}
} or []
MC/DC0%0/1
eval {
do {
[$self->git_repo->head->target]
}
} or []
eval {
do {
[$self->git_repo->head->target]
}
}
Truth table50%1/2
A
A= eval {
do {
[$self->git_repo->head->target]
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | : croak "Can't commit without a branch or use_workdir or option create_branch"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # undef final param means don't update HEAD | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 34 | ▶ | my $commit= Git::Raw::Commit->create($repo, $message, $author, $committer, $parents, $self->tree, undef) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | or croak "commit failed"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 34 | ▶ | if ($opts{create_branch}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 28 | $branch= $repo->branch($opts{create_branch}, $commit); | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 28 | $self->branch($branch); | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | } elsif ($branch) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # Update the branch | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 6 | $branch->target($commit); | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 34 | ▶ | $repo->head($branch) if $branch && $update_head; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$branch and $update_head
MC/DC50%1/2
$branch and $update_head
$branch
$update_head
Truth table66%2/3
A and B
A= $branchB= $update_head
| |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # persist the index state to disk, which clears the staged changes and brings the index | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # in sync with the commit | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 34 | ▶ | $repo->index->write if $self->use_workdir; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 34 | $self->has_changes(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 189 | 34 | return $commit; | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||