Git::R...sitory(3pm)
π Git::Raw::Repository π
okay so bestie, this is the manual for Git::Raw::Repository from the User Contributed Perl Documentation. It's giving Git repository class energy, and we're gonna go through every single detail together. periodt. π
β¨ NAME β¨
Git::Raw::Repository β it's literally a Git repository class, no cap. π¦
πΈ VERSION πΈ
version 0.90 β that's the vibe check, bestie. β¨
π SYNOPSIS π
okay so like, here's a whole mood of how you use this thing:
use Git::Raw;
# clone a Git repository
my $url = 'git://github.com/jacquesg/p5-Git-Raw.git';
my $callbacks = {
'transfer_progress' => sub {
my ($total_objects, $received_objects, $local_objects, $total_deltas,
$indexed_deltas, $received_bytes) = @_;
print "Objects: $received_objects/$total_objects", "\n";
print "Received: ", int($received_bytes/1024), "KB", "\n";
}
};
my $repo = Git::Raw::Repository -> clone($url, 'p5-Git-Raw', {}, {
'callbacks' => $callbacks
});
# print all the tags of the repository
foreach my $tag ($repo -> tags) {
say $tag -> name;
}
# merge a reference
my $ref = Git::Raw::Reference -> lookup('HEAD', $repo);
$repo -> merge ($ref);
my @conflicts = $repo -> index -> conflicts;
print "Got ", scalar (@conflicts), " conflicts!\n";
π DESCRIPTION π
A Git::Raw::Repository represents a Git repository. That's the whole mood. π
WARNING: The API of this module is unstable and may change without warning (any change will be appropriately documented in the changelog). No cap, this is important β it might change on you, bestie. π
π METHODS π
π§ init( $path, $is_bare )
Initialize a new repository at $path. The full signature is init( $path, $is_bare ). Slay. π
π¦ clone( $url, $path, %opts, [%fetch_opts, %checkout_opts])
Clone the repository at $url to $path. Here's the tea on valid fields for the %opts hash:
bareβ If true (default is false) create a bare repository. πcheckout_branchβ The name of the branch to checkout (default is to use the remote's HEAD).disable_checkoutβ If true (default is false) files will not be checked out after the clone completes.callbacksβremote_createβ Remote customization callback. If a non-default remote is required, i.e. a remote with a remote name other than 'origin', this callback should be used. The callback receives aGit::Raw::Repositoryobject, a string containing the default name for the remote, typically 'origin', and a string containing the URL of the remote. This callback should return aGit::Raw::Remoteobject. The returned object and the repository object passed to this callback are ephemeral. Note: Do not take any references to it, as it may be freed internally. π±
See "Git::Raw::Remote->fetch()" for valid %fetch_opts values and "Git::Raw::Repository->checkout()" for valid %checkout_opts values.
π open( $path )
Open the repository at $path.
π discover( $path )
Discover the path to the repository directory given a subdirectory.
β¨ new( )
Create a new repository with neither backends nor config object.
π« config( )
Retrieve the default Git::Raw::Config of the repository.
π«Ά commondir( )
Get the path of the shared common directory for this repository.
π§ is_worktree( )
Check if the repository is a linked work tree.
π index( [$new_index] )
Retrieve the index of the repository. If $new_index is passed, it will be used as the index of the repository. If $new_index is undef the index associated with the repository will be disassociated. Returns a Git::Raw::Index object or undef if index has been disassociated as part of the call.
π¦ odb( [$new_odb] )
Retrieve the object database of the repository. If $odb is passed, it will be used as the object database. Returns a Git::Raw::Odb object.
π head( [$new_head] )
Retrieve the Git::Raw::Reference pointed by the HEAD of the repository. If the Git::Raw::Reference $new_head is passed, the HEAD of the repository will be changed to point to it.
πΈ head_for_worktree( $worktree )
Retrieve the Git::Raw::Reference pointed by the HEAD of $worktree.
π₯ detach_head( $commitish )
Make the repository HEAD point directly to a commit. $commitish should be peelable to a Git::Raw::Commit object, that is, it should be a Git::Raw::Commit or Git::Raw::Reference object, or alternatively a commit id or commit id prefix.
π lookup( $id )
Retrieve the object corresponding to $id.
π¦ checkout( $object, %opts )
Updates the files in the index and working tree to match the content of $object. Valid fields for the %opts hash are:
checkout_strategyβ Hash representing the desired checkout strategy. Valid fields are:noneβ Dry-run checkout strategy. It doesn't make any changes, but checks for conflicts.forceβ Take any action to make the working directory match the target (pretty much the opposite ofnone).safe_createβ Recreate missing files.safeβ Make only modifications that will not lose changes (to be used in order to simulategit checkout).allow_conflictsβ Apply safe updates even if there are conflicts.remove_untrackedβ Remove untracked files from the working directory.remove_ignoredβ Remove ignored files from the working directory.update_onlyβ Only update files that already exist (files won't be created or deleted).dont_update_indexβ Do not write the updated files' info to the index.dont_remove_existingβ Don not overwrite existing files or folders.dont_write_indexβ Prevent writing of the index upon completion.no_refreshβ Do not reload the index and git attrs from disk before operations.skip_unmergedβ Skip files with unmerged index entries, instead of treating them as conflicts.
notifyβ Notification flags for the notify callback. A list of the following options:conflictβ Notifies about conflicting paths.dirtyβ Notifies about files that don't need an update but no longer match the baseline. Core git displays these files when checkout runs, but won't stop the checkout.updatedβ Notification on any file changed.untrackedβ Notification about untracked files.ignoredβ Notifies about ignored files.allβ All of the above.
callbacksβ Hash containing progress and notification callbacks. Valid fields are:notifyβ This callback is called for each file matching one of thenotifyoptions selected. It runs before modifying any files on disk. This callback should return a non-zero value should the checkout be cancelled. The callback receives a string containing the path of the file$pathand an array reference containing the reason$why.progressβ The callback to be invoked as a file is checked out. The callback receives a string containing the path of the file$path, an integer$completed_stepsand an integer$total_steps.
pathsβ An optional array representing the list of files that should be checked out. Ifpathsis not specified, all files will be checked out (default).our_labelβ The name of the "our" side of conflicts.their_labelβ The name of the "their" side of conflicts.ancestor_labelβ The name of the common ancestor side of conflicts.target_directoryβ Alternative checkout path to the working directory.
Example:
$repo -> checkout($repo -> head -> target, {
'checkout_strategy' => { 'safe' => 1 },
'notify' => [ 'all' ],
'callbacks' => {
'notify' => sub {
my ($path, $why) = @_;
print "File: $path: ", join(' ', @$why), "\n";
},
'progress' => sub {
my ($path, $completed_steps, $total_steps) = @_;
print "File: $path", "\n" if defined ($path);
print "Progress: $completed_steps/$total_steps", "\n";
}
},
'paths' => [ 'myscript.pl' ]
});
πΈ reset( $target, %opts )
Reset the current HEAD to the given commit. Valid fields for the %opts hash are:
typeβ Set the type of the reset to be performed. Valid values are:soft(the head will be moved to the commit),mixed(trigger a soft reset and replace the index with the content of the commit tree) orhard(trigger amixedreset and the working directory will be replaced with the content of the index).pathsβ List of entries in the index to be updated from the target commit tree. This is particularly useful to implementgit reset HEAD -- file filebehaviour. Note, if this parameter is specified, a value ofmixedwill be used fortype(settingtypetosoftorhardhas no effect).
π¦ status( %opts, [$file, $file, ...] )
Retrieve the status of files in the index and/or working directory. This function returns a hash reference with an entry for each $file, or all files if no file parameters are provided. Each $file entry has a list of flags, which may include: index_new, index_modified, index_deleted, index_renamed, worktree_new, worktree_modified, worktree_deleted, worktree_renamed, worktree_unreadable, conflicted and ignored.
If $file has been renamed in either the index or worktree or both, $file will also have a corresponding entry index and/or worktree, containing the previous filename old_file.
Valid fields for the %opts hash are:
flagsβ Flags for the status. Valid values include:include_untrackedβ Callbacks should be made on untracked files. These will only be made if the workdir files are included in the$showoption.include_ignoredβ Callbacks should be made on ignored files. These will only be made if the ignored files get callbacks.include_unmodifiedβ Include even unmodified files.exclude_submodules
β¦still deep inside that flags list, we didn't go anywhere π
- Submodules get skipped, bestie. This only applies if there are no pending typechanges to the submodule (either from or to another type).
recurse_untracked_dirsβ all files in untracked directories should be included π¦. Normally, if an entire directory is new, then just the top-level directory is included (with a trailing slash on the entry name). This flag includes all of the individual files in the directory instead.disable_pathspec_matchβ each$fileyou specify should be treated as a literal path, and not as a pathspec pattern. No pattern matching, just the exact path you typed β¨recurse_ignored_dirsβ the contents of ignored directories should be included in the status π. This is like doinggit ls-files -o -i --exclude-standardwith core git.renames_head_to_indexβ rename detection should be processed between the head and the index.renames_index_to_workdirβ rename detection should be run between the index and the working directory.sort_case_sensitivelyβ override the native case sensitivity for the file system and force the output to be in case-sensitive order π€sort_case_insensitivelyβ override the native case sensitivity for the file system and force the output to be in case-insensitive order.renames_from_rewritesβ rename detection should include rewritten files.no_refreshβ bypass the default status behavior of doing a "soft" index reload (i.e. reloading the index data if the file on disk has been modified outsideGit::Raw) πupdate_indexβ refresh the stat cache in the index for files that are unchanged but have out-of-date stat information in the index. It will result in less work being done on subsequent calls tostatusπ₯. This is mutually exclusive with theno_refreshoption β pick one, bestie.include_unreadableβ include unreadable files.include_unreadable_as_untrackedβ include unreadable files as untracked files.
showβ one of the following values (defaults toindex_and_worktree):index_and_worktreeindexworktree
Example π
my $opts = {
'flags' => {
'include_untracked' => 1,
'renames_head_to_index' => 1,
'renames_index_to_workdir' => 1,
},
'show' => 'index_and_worktree'
};
my $file_statuses = $repo -> status($opts);
while (my ($file, $status) = each %$file_statuses) {
my $flags = $status -> {'flags'};
print "File: $file: Status: ", join (' ', @$flags), "\n";
if (grep { $_ eq 'index_renamed' } @$flags) {
print "Index previous filename: ",
$status -> {'index'} -> {'old_file'}, "\n";
}
if (grep { $_ eq 'worktree_renamed' } @$flags) {
print "Worktree previous filename: ",
$status -> {'worktree'} -> {'old_file'}, "\n";
}
}
merge_base( @objects )
Find the merge base between @objects π§. Every element in @objects should be peelable to a Git::Raw::Commit object β translation: it should be a Git::Raw::Commit or Git::Raw::Reference object, or alternatively a commit id or commit id prefix. That's the whole gig.
merge_analysis( $reference )
Analyzes the given $reference and figures out the opportunities for merging them into the HEAD of the repository π. This function returns an array reference with optional members normal, up_to_date, fast_forward and/or unborn.
normalβ a "normal" merge. BothHEADand the given merge input have diverged from their common ancestor. The divergent commits must be merged.up_to_dateβ all given merge inputs are reachable fromHEAD, meaning the repository is up-to-date and no merge needs to be performed. Slay, nothing to do πfast_forwardβ the given merge input is a fast-forward fromHEADand no merge needs to be performed. Instead, the given merge input may be checked out.unbornβ theHEADof the current repository is "unborn" and does not point to a valid commit. No merge can be performed, but the caller may wish to simply setHEADto the target commit(s).
merge( $ref, [\%merge_opts, \%checkout_opts])
Merge the given $ref into HEAD, writing the results into the working directory π. Any changes are staged for commit and any conflicts are written to the index. The index should be inspected for conflicts after this method completes and any conflicts should be resolved π. At this stage a commit may be created to finalise the merge.
flagsβ merge flags. Valid values include:find_renamesβ detect renames.
file_flagsβ see"Git::Raw::Index->merge()"for options.favorβ specify content automerging behaviour. Valid values areours,theirs, andunion.rename_thresholdβ similarity metric for considering a file renamed (default is 50).target_limitβ maximum similarity sources to examine (overrides themerge.renameLimitconfiguration entry) (default is 200).
Example π
my $branch = Git::Raw::Branch -> lookup($repo, 'branch', 1);
my $analysis = $repo -> merge_analysis($branch);
my $merge_opts = {
'favor' => 'theirs'
};
my $checkout_opts = {
'checkout_strategy' => {
'force' => 1
}
};
$repo -> merge($branch1, $merge_opts, $checkout_opts);
ignore( $rules )
Add an ignore rule to the repository πΈ. The format of the rules is the same one of the .gitignore file (see the gitignore(5) manpage). Example π
$repo -> ignore("*.o\n");
path_is_ignored( $path )
Checks the ignore rules to see if they would apply to the given file π«Ά. This indicates if the file would be ignored regardless of whether the file is already in the index or committed to the repository. Vibe check, but for ignore rules.
diff( [\%diff_opts] )
Compute the Git::Raw::Diff between the repo's default index and another tree β¨. Valid fields for the %diff_opts hash are:
treeβ if provided, the diff is computed betweentreeand the repo's default index. The default is the repo's working directory.flagsβ flags for generating the diff. Valid values include:reverseβ reverse the sides of the diff.include_ignoredβ include ignored files in the diff.include_typechangeβ enable the generation of typechange delta records.recurse_ignored_dirsβ even ifinclude_ignoredis specified, an entire ignored directory will be marked with only a single entry in the diff. This flag adds all files under the directory as ignored entries, too.include_untrackedβ include untracked files in the diff.recurse_untracked_dirsβ even ifinclude_untrackedis specified, an entire untracked directory will be marked with only a single entry in the diff (core git behaviour). This flag adds all files under untracked directories as untracked entries, too.ignore_filemodeβ ignore file mode changes.ignore_caseβ use case insensitive filename comparisons.ignore_submodulesβ treat all submodules as unmodified.ignore_whitespaceβ ignore all whitespace.ignore_whitespace_changeβ ignore changes in amount of whitespace.ignore_whitespace_eolβ ignore whitespace at end of line.skip_binary_checkβ disable updating of the binary flag in delta records. This is useful when iterating over a diff if you don't need hunk and data callbacks and want to avoid having to load file completely.enable_fast_untracked_dirsβ when diff finds an untracked directory, to match the behavior of core git, it scans the contents for ignored and untracked files. If all contents are ignore, then the directory is ignored. If any contents are not ignored, then the directory is untracked. This is extra work that may not matter in many cases π. This flag turns off that scan and immediately labels an untracked directory as untracked (changing the behavior to not match core git).show_untracked_contentβ include the content of untracked files. This impliesinclude_untracked.show_unmodifiedβ include the names of unmodified files.patienceβ use the "patience diff" algorithm.minimalβ take extra time to find minimal diff.show_binaryβ include the necessary deflate / delta information so thatgit applycan apply given diff information to binary files.force_textβ treat all files as text, disabling binary attributes and detection.force_binaryβ treat all files as binary, disabling text diffs.
prefixaβ the virtual "directory" to prefix to old file names in hunk headers. (Default isa.)bβ the virtual "directory" to prefix to new file names in hunk headers. (Default isb.)
context_linesβ the number of unchanged lines that define the boundary of a hunk (and to display before and after)interhunk_linesβ the maximum number of unchanged lines between hunk boundaries before the hunks will be merged into a one.pathsβ a list of paths to constrain diff.
blob( $buffer )
Create a new Git::Raw::Blob. Shortcut for Git::Raw::Blob->create(). Obsessed π
branch( $name, $target )
Create a new Git::Raw::Branch. Shortcut for Git::Raw::Branch->create().
branches( [$type] )
Grab a list of Git::Raw::Branch objects, bestie π The $type you hand over can be "local", "remote" or "all" β pick your fighter fr fr.
commit( $msg, $author, $committer, \@parents, $tree [, $update_ref ] )
Make a brand new Git::Raw::Commit β¨ It's just a shortcut for Git::Raw::Commit->create(), so you know it's lowkey the same thing with a nicer outfit π
tag( $name, $msg, $tagger, $target )
Create a fresh Git::Raw::Tag π Shortcut for Git::Raw::Tag->create(). Iconic behaviour honestly.
tags( [$type] )
Returns the list of annotated and/or lightweight tag objects π·οΈ Your $type can be "all", "annotated" or "lightweight". Not me being able to filter tags, we love a flexible queen π
stash( $repo, $msg )
Save your local modifications off into a new stash π Shortcut for Git::Raw::Stash->save(). Your messy WIP? Hidden. Your working tree? Clean. Main character energy.
remotes( )
Get the list of Git::Raw::Remote objects π
refs( )
Get the list of Git::Raw::Reference objects β
walker( )
Create a new Git::Raw::Walker πΆββοΈπΆ Shortcut for Git::Raw::Walker->create(). Go take a little walk through your history, you deserve it.
path( )
Retrieves the complete path of the repository π no cap, the whole thing.
workdir( [$new_dir] )
Retrieves the working directory of the repository ποΈ And if you pass $new_dir, the repository's working directory gets set to that directory. Two jobs, one method, she's doing both π
blame( $path )
Pulls blame info for $path ππ Returns a Git::Raw::Blame object. Time to find out who wrote that line, iykyk.
cherry_pick( $commit, [\%merge_opts, \%checkout_opts, $mainline] )
Cherry-pick that $commit, producing changes in the index and the working directory πβ¨ Peep Git::Raw::Repository->merge() for the valid %merge_opts and %checkout_opts values β that's where the deets live. And for merge commits, $mainline specifies the parent.
revert( $commit, [\%merge_opts, \%checkout_opts, $mainline] )
Revert the given $commit, producing changes in the index and the working directory β©οΈ Same deal as above: check Git::Raw::Repository->merge() for valid %merge_opts and %checkout_opts values. For merge commits, $mainline specifies the parent. Undoing things is self-care, periodt.
revparse( $spec )
Parses the revision string $spec to for "from", "to" and "intent" π Returns a list of objects when you're in list context, and the number of objects parsed from $spec when you're in scalar context.
my ($from, $to) = $repo -> revparse('HEAD~..HEAD');
print "Range is $from -> $to", "\n";
state( )
Figure out what state the repo is in π«Ά One of these values comes back:
"none"β Normal state. Everything is chill β¨"merge"β Repository is in a merge."revert"β Repository is in a revert."cherry_pick"β Repository is in a cherry-pick π"bisect"β Repository is bisecting."rebase"β Repository is rebasing."rebase_interactive"β Repository is in an interactive rebase."rebase_merge"β Repository is in an rebase merge."apply_mailbox"β Repository is applying patches π¬"mailbox_or_rebase"β Repository is applying patches or rebasing.
state_cleanup( )
Removes all the metadata associated with an ongoing command like merge, revert, cherry-pick, etc. π§Ή Big cleanup energy. Wipe the slate, start fresh, we're healing π
message( )
Retrieves the content of git's prepared message, i.e. .git/MERGE_MSG π
is_empty( )
Checks if the repository is empty π³οΈ
is_bare( )
Checks if the repository is bare π
is_shallow( )
Checks if the repository is a shallow clone π
is_head_detached( )
Checks if the repository's HEAD is detached β that is, it points directly to a commit π Your HEAD is out here with no branch to hold onto, free-floating, unbothered, no thoughts.
π AUTHOR π
Alessandro Ghedini <alexbio@cpan.org> π
Jacques Germishuys <jacquesg@cpan.org> π
π LICENSE AND COPYRIGHT π
Copyright 2012 Alessandro Ghedini.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
And that's a wrap, bestie π This lil tutorial came to you from perl v5.42.3, dated 2026-08-19, and it lives its life as Git::R...sitory(3pm). Go forth and slay your git objects π
π¦πΈ
π¦ where this page comes from
- ubuntu stonking: libgit-raw-perl 0.90+ds-3build3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms