.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Git::Wrapper 3pm" .TH Git::Wrapper 3pm "2022-12-11" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Git::Wrapper \- Wrap git(7) command\-line interface .SH "VERSION" .IX Header "VERSION" version 0.048 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& my $git = Git::Wrapper\->new(\*(Aq/var/foo\*(Aq); \& \& $git\->commit(...) \& print $_\->message for $git\->log; \& \& # specify which git binary to use \& my $git = Git::Wrapper\->new({ \& dir => \*(Aq/var/foo\*(Aq , \& git_binary => \*(Aq/path/to/git/bin/git\*(Aq , \& }); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Git::Wrapper provides an \s-1API\s0 for \fBgit\fR\|(7) that uses Perl data structures for argument passing, instead of CLI-style \f(CW\*(C`\-\-options\*(C'\fR as Git does. .SH "METHOD INVOCATION" .IX Header "METHOD INVOCATION" Except as documented, every git subcommand is available as a method on a Git::Wrapper object. Replace any hyphens in the git command with underscores (for example, \f(CW\*(C`git init\-db\*(C'\fR would become \f(CW\*(C`$git\->init_db\*(C'\fR). .SS "Method Arguments" .IX Subsection "Method Arguments" Methods accept a combination of hashrefs and scalars, which is used to build the command used to invoke git. Arguments passed in hashrefs will be automatically parsed into option pairs, but the ordering of these in the resulting shell command is not guaranteed (with the exception of options with a leading '\-'; see below). Options that are passed as plain scalars will retain their order. Some examples may help clarify. This code: .PP .Vb 1 \& $git\->commit({ message => "stuff" , all => 1 }); .Ve .PP may produce this shell command: .PP .Vb 1 \& git commit \-\-all \-\-message="stuff" .Ve .PP This code, however: .PP .Vb 1 \& $git\->commit(qw/ \-\-message "stuff" / , { all => 1 }); .Ve .PP will always produce this shell command: .PP .Vb 1 \& git commit \-\-message "stuff" \-\-all .Ve .PP In most cases, this exact control over argument ordering is not needed and simply passing all options as part of a hashref, and all other options as additional list arguments, will be sufficient. In some cases, however, the ordering of options to particular git sub-commands is significant, resulting in the need for this level of control. .PP \&\fIN.b.\fR Options that are given with a leading '\-' (with the exception of special options noted below) are applied as arguments to the \f(CW\*(C`git\*(C'\fR command itself; options without a leading '\-' are applied as arguments to the sub-command. For example: .PP .Vb 1 \& $git\->command({ \-foo => 1 , bar => 2 }); .Ve .PP invokes the command line .PP .Vb 1 \& git \-\-foo=1 command \-\-bar=2 .Ve .PP \&\fIN.b.\fR Because of the way arguments are parsed, should you need to pass an explicit '0' value to an option (for example, to have the same effect as \&\f(CW\*(C`\-\-abbrev=0\*(C'\fR on the command line), you should pass it with a leading space, like so: .PP .Vb 1 \& $git\->describe({ abbrev => \*(Aq 0\*(Aq }; .Ve .PP To pass content via \s-1STDIN,\s0 use the \-STDIN option: .PP .Vb 1 \& $git\->hash_object({ stdin => 1, \-STDIN => \*(Aqcontent to hash\*(Aq }); .Ve .PP Output is available as an array of lines, each chomped. .PP .Vb 1 \& @sha1s_and_titles = $git\->rev_list({ all => 1, pretty => \*(Aqoneline\*(Aq }); .Ve .PP \fIPassing stringify-able objects as arguments\fR .IX Subsection "Passing stringify-able objects as arguments" .PP Objects may be passed in the place of scalars, assuming those objects overload stringification in such a way as to produce a useful value. However, relying on this stringification is discouraged and likely to be officially deprecated in a subsequent release. Instead, if you have an object that stringifies to a meaningful value (\fIe.g.\fR, a Path::Class object), you should stringify it yourself before passing it to \f(CW\*(C`Git::Wrapper\*(C'\fR methods. .SS "Error handling" .IX Subsection "Error handling" If a git command exits nonzero, a \f(CW\*(C`Git::Wrapper::Exception\*(C'\fR object will be thrown (via \f(CW\*(C`die\*(C'\fR) and may be captured via \f(CW\*(C`eval\*(C'\fR or Try::Tiny, for example. .PP The error object has three useful methods: .IP "\(bu" 4 error .Sp Returns the full error message reported by the resulting git command sent to \&\f(CW\*(C`STDERR\*(C'\fR. This method should not be used as a success/failure check, as \&\f(CW\*(C`git\*(C'\fR will sometimes produce output on \s-1STDERR\s0 when a command is successful. .IP "\(bu" 4 output .Sp Returns the full output generated by the git command that is sent to \&\f(CW\*(C`STDOUT\*(C'\fR. This method should not be used as a success/failure check, as \&\f(CW\*(C`git\*(C'\fR will frequently not have any output with a successful command. .IP "\(bu" 4 status .Sp Returns the non-zero exit code reported by git on error. .PP \fIUsing Try::Tiny\fR .IX Subsection "Using Try::Tiny" .PP Try::Tiny is the recommended way to catch exception objects thrown by Git::Wrapper. .PP .Vb 1 \& use Try::Tiny \& \& my $git = Git::Wrapper\->new(\*(Aq/path/to/my/repo\*(Aq); \& \& try { \& # equivalent to, "git \-\-non\-existent\-option=1" on the commandline \& $git\->status({ "non\-existent\-option"=>1 }); \& } \& catch { \& # print STERR from erroneous git command \& print $_\->error; \& \& # print STOUT from git command \& print $_\->output; \& \& # print non\-zero exist status of git processo \& print $_\->status; \& \& # quotes are overloaded, so: \& print "$_"; # equivalent to $_\->error \& }; .Ve .PP \fIUsing \f(CI\*(C`eval\*(C'\fI\fR .IX Subsection "Using eval" .PP If for some reason you are unable to use Try::Tiny, it is also possible to use the \f(CW\*(C`eval\*(C'\fR function to catch exception objects. \fB\s-1THIS IS NOT RECOMMENDED\s0!\fR .PP .Vb 1 \& my $git = Git::Wrapper\->new(\*(Aq/path/to/my/repo\*(Aq); \& \& my $ok = eval { \& # equivalent to, "git \-\-non\-existent\-option=1" on the commandline \& $git\->status({ "non\-existent\-option"=>1 }); \& 1; \& }; \& \& if ($@ and ref $@ eq q{Git::Wrapper::Exception}) { \& # print STERR from erroneous git command \& print $@\->error; \& \& # print STOUT from git command \& print $@\->output; \& \& # print non\-zero exist status of git processo \& print $@\->status; \& \& # quotes are overloaded, so: \& print "$@"; # equivalent to $@\->error \& } .Ve .SH "METHODS" .IX Header "METHODS" .SS "new" .IX Subsection "new" .Vb 2 \& my $git = Git::Wrapper\->new($dir); \& my $git = Git::Wrapper\->new({ dir => $dir , git_binary => \*(Aq/path/to/git\*(Aq }); \& \& # To force the git binary location \& my $git = Git::Wrapper\->new($dir, \*(Aqgit_binary\*(Aq => \*(Aq/usr/local/bin/git\*(Aq); \& \& # prints the content of OUT and ERR to STDOUT and STDERR \& # after a command is run \& my $git = Git::Wrapper\->new($dir, autoprint => 1); .Ve .SS "git" .IX Subsection "git" .Vb 1 \& print $git\->git; # /path/to/git/binary/being/used .Ve .SS "dir" .IX Subsection "dir" .Vb 1 \& print $git\->dir; # /var/foo .Ve .SS "version" .IX Subsection "version" .Vb 1 \& my $version = $git\->version; # 1.6.1.4.8.15.16.23.42 .Ve .SS "branch" .IX Subsection "branch" .Vb 1 \& my @branches = $git\->branch; .Ve .PP This command intentionally disables \s-1ANSI\s0 color highlighting in the output. If you want \s-1ANSI\s0 color highlighting, you'll need to bypass via the \s-1\fBRUN\s0()\fR method (see below). .SS "log" .IX Subsection "log" .Vb 1 \& my @logs = $git\->log; .Ve .PP Instead of giving back an arrayref of lines, the \f(CW\*(C`log\*(C'\fR method returns a list of \f(CW\*(C`Git::Wrapper::Log\*(C'\fR objects. .PP There are five methods in a \f(CW\*(C`Git::Wrapper::Log\*(C'\fR objects: .IP "\(bu" 4 id .IP "\(bu" 4 author .IP "\(bu" 4 date .IP "\(bu" 4 message .IP "\(bu" 4 modifications .Sp Only populated with when \f(CW\*(C`raw => 1\*(C'\fR option is set; see \*(L"Raw logs\*(R" below. .PP \fIRaw logs\fR .IX Subsection "Raw logs" .PP Calling the \f(CW\*(C`log\*(C'\fR method with the \f(CW\*(C`raw => 1\*(C'\fR option set, as below, will do additional parsing to populate the \f(CW\*(C`modifications\*(C'\fR attribute on each \&\f(CW\*(C`Git::Wrapper::Log\*(C'\fR object. This method returns a list of \&\f(CW\*(C`Git::Wrapper::File::RawModification\*(C'\fR objects, which can be used to get filenames, permissions, and other metadata associated with individual files in the given commit. A short example, to loop over all commits in the log and print the filenames that were changed in each commit, one filename per file: .PP .Vb 8 \& my @logs = $git\->log({ raw => 1 }); \& foreach my $log ( @logs ) { \& say "In commit \*(Aq" . $log\->id . "\*(Aq, the following files changed:"; \& my @mods = $log\->modifications; \& foreach my $mod ( @mods ) { \& say "\et" . $mod\->filename; \& } \& } .Ve .PP Note that some commits (e.g., merge commits) will not contain any file changes. The \f(CW\*(C`modifications\*(C'\fR method will return an empty list in that case. .PP \fICustom log formats\fR .IX Subsection "Custom log formats" .PP \&\f(CW\*(C`log\*(C'\fR will throw an exception if it is passed the \f(CW\*(C`\-\-format\*(C'\fR option. The reason for this has to do with the fact that the parsing of the full log output into \f(CW\*(C`Git::Wrapper::Log\*(C'\fR objects assumes the default format provided by `git` itself. Passing \f(CW\*(C`\-\-format\*(C'\fR to the underlying `git log` method affects this assumption and the output is no longer able to be processed as intented. .PP If you wish to specify a custom log format, please use the \s-1RUN\s0 method directly. The caller will be supplied with the full log output. From there, the caller may process the output as it wishes. .SS "has_git_in_path" .IX Subsection "has_git_in_path" This method returns a true or false value indicating if there is a 'git' binary in the current \f(CW$PATH\fR. .SS "supports_status_porcelain" .IX Subsection "supports_status_porcelain" .SS "supports_log_no_abbrev_commit" .IX Subsection "supports_log_no_abbrev_commit" .SS "supports_log_no_expand_tabs" .IX Subsection "supports_log_no_expand_tabs" .SS "supports_log_raw_dates" .IX Subsection "supports_log_raw_dates" .SS "supports_hash_object_filters" .IX Subsection "supports_hash_object_filters" These methods return a true or false value (1 or 0) indicating whether the git binary being used has support for these options. (The '\-\-porcelain' option on \&'git status', the '\-\-no\-abbrev\-commit', '\-\-no\-expand\-tabs', and '\-\-date=raw' options on 'git log', and the '\-\-no\-filters' option on 'git hash\-object' respectively.) .PP These are primarily for use in this distribution's test suite, but may also be useful when writing code using Git::Wrapper that might be run with different versions of the underlying git binary. .SS "status" .IX Subsection "status" When running with an underlying git binary that returns false for the \&\*(L"supports_status_porcelain\*(R" method, this method will act like any other wrapped command: it will return output as an array of chomped lines. .PP When running with an underlying git binary that returns true for the \&\*(L"supports_status_porcelain\*(R" method, this method instead returns an instance of Git::Wrapper::Statuses: .PP .Vb 1 \& my $statuses = $git\->status; .Ve .PP Git::Wrapper:Statuses has two public methods. First, \f(CW\*(C`is_dirty\*(C'\fR: .PP .Vb 1 \& my $dirty_flag = $statuses\->is_dirty; .Ve .PP which returns a true/false value depending on whether the repository has any uncommitted changes. .PP Second, \f(CW\*(C`get\*(C'\fR: .PP .Vb 1 \& my @status = $statuses\->get($group) .Ve .PP which returns an array of Git::Wrapper::Status objects, one per file changed. .PP There are four status groups, each of which may contain zero or more changes. .IP "\(bu" 4 indexed : Changed & added to the index (aka, will be committed) .IP "\(bu" 4 changed : Changed but not in the index (aka, won't be committed) .IP "\(bu" 4 unknown : Untracked files .IP "\(bu" 4 conflict : Merge conflicts .PP Note that a single file can occur in more than one group. E.g., a modified file that has been added to the index will appear in the 'indexed' list. If it is subsequently further modified it will additionally appear in the 'changed' group. .PP A Git::Wrapper::Status object has three methods you can call: .PP .Vb 1 \& my $from = $status\->from; .Ve .PP The file path of the changed file, relative to the repo root. For renames, this is the original path. .PP .Vb 1 \& my $to = $status\->to; .Ve .PP Renames returns the new path/name for the path. In all other cases returns an empty string. .PP .Vb 1 \& my $mode = $status\->mode; .Ve .PP Indicates what has changed about the file. .PP Within each group (except 'conflict') a file can be in one of a number of modes, although some modes only occur in some groups (e.g., 'added' never appears in the 'unknown' group). .IP "\(bu" 4 modified .IP "\(bu" 4 added .IP "\(bu" 4 deleted .IP "\(bu" 4 renamed .IP "\(bu" 4 copied .IP "\(bu" 4 conflict .PP All files in the 'unknown' group will have a mode of 'unknown' (which is redundant but at least consistent). .PP The 'conflict' group instead has the following modes. .IP "\(bu" 4 \&'both deleted' : deleted on both branches .IP "\(bu" 4 \&'both added' : added on both branches .IP "\(bu" 4 \&'both modified' : modified on both branches .IP "\(bu" 4 \&'added by us' : added only on our branch .IP "\(bu" 4 \&'deleted by us' : deleted only on our branch .IP "\(bu" 4 \&'added by them' : added on the branch we are merging in .IP "\(bu" 4 \&'deleted by them' : deleted on the branch we are merging in .PP See git-status man page for more details. .PP \fIExample\fR .IX Subsection "Example" .PP .Vb 10 \& my $git = Git::Wrapper\->new(\*(Aq/path/to/git/repo\*(Aq); \& my $statuses = $git\->status; \& for my $type (qw) { \& my @states = $statuses\->get($type) \& or next; \& print "Files in state $type\en"; \& for (@states) { \& print \*(Aq \*(Aq, $_\->mode, \*(Aq \*(Aq, $_\->from; \& print \*(Aq renamed to \*(Aq, $_\->to \& if $_\->mode eq \*(Aqrenamed\*(Aq; \& print "\en"; \& } \& } .Ve .SS "\s-1RUN\s0" .IX Subsection "RUN" This method bypasses the output rearranging performed by some of the wrapped methods described above (i.e., \f(CW\*(C`log\*(C'\fR, \f(CW\*(C`status\*(C'\fR, etc.). This can be useful in various situations, such as when you want to produce a particular log output format that isn't compatible with the way \f(CW\*(C`Git::Wrapper\*(C'\fR constructs \&\f(CW\*(C`Git::Wrapper::Log\*(C'\fR, or when you want raw \f(CW\*(C`git status\*(C'\fR output that isn't parsed into a \f(CW\*(C`Git::Wrapper::Status\*(C'\fR object. .PP This method should be called with an initial string argument of the \f(CW\*(C`git\*(C'\fR subcommand you want to run, followed by a hashref containing options and their values, and then a list of any other arguments. .PP \fIExample\fR .IX Subsection "Example" .PP .Vb 1 \& my $git = Git::Wrapper\->new( \*(Aq/path/to/git/repo\*(Aq ); \& \& # the \*(Aqlog\*(Aq method returns Git::Wrapper::Log objects \& my @log_objects = $git\->log(); \& \& # while \*(AqRUN(\*(Aqlog\*(Aq)\*(Aq returns an array of chomped lines \& my @log_lines = $git\->RUN(\*(Aqlog\*(Aq); \& \& # getting the full of commit SHAs via \`git log\` by using the \*(Aq\-\-format\*(Aq option \& my @log_lines = $git\->RUN(\*(Aqlog\*(Aq, \*(Aq\-\-format=%H\*(Aq); .Ve .ie n .SS "\s-1AUTOPRINT\s0( $enabled )" .el .SS "\s-1AUTOPRINT\s0( \f(CW$enabled\fP )" .IX Subsection "AUTOPRINT( $enabled )" If set to \f(CW\*(C`true\*(C'\fR, the content of \f(CW\*(C`OUT\*(C'\fR and \f(CW\*(C`ERR\*(C'\fR will automatically be printed on, respectively, \s-1STDOUT\s0 and \s-1STDERR\s0 after a command is run. .SS "\s-1ERR\s0" .IX Subsection "ERR" After a command has been run, this method will return anything that was sent to \f(CW\*(C`STDERR\*(C'\fR, in the form of an array of chomped lines. This information will be cleared as soon as a new command is executed. This method should \fB*NOT*\fR be used as a success/failure check, as \f(CW\*(C`git\*(C'\fR will sometimes produce output on \&\s-1STDERR\s0 when a command is successful. .SS "\s-1OUT\s0" .IX Subsection "OUT" After a command has been run, this method will return anything that was sent to \f(CW\*(C`STDOUT\*(C'\fR, in the form of an array of chomped lines. It is identical to what is returned from the method call that runs the command, and is provided simply for symmetry with the \f(CW\*(C`ERR\*(C'\fR method. This method should \fB*NOT*\fR be used as a success/failure check, as \f(CW\*(C`git\*(C'\fR will frequently not have any output with a successful command. .SH "COMPATIBILITY" .IX Header "COMPATIBILITY" On Win32 Git::Wrapper is incompatible with msysGit installations earlier than Git\-1.7.1\-preview20100612 due to a bug involving the return value of a git command in cmd/git.cmd. If you use the msysGit version distributed with GitExtensions or an earlier version of msysGit, tests will fail during installation of this module. You can get the latest version of msysGit on the Google Code project page: .SH "ENVIRONMENT VARIABLES" .IX Header "ENVIRONMENT VARIABLES" Git::Wrapper normally uses the first 'git' binary in your path. The original override provided to change this was by setting the \s-1GIT_WRAPPER_GIT\s0 environment variable. Now that object creation accepts an override, you are encouraged to instead pass the binary location (git_binary) to new on object creation. .SH "SEE ALSO" .IX Header "SEE ALSO" VCI::VCS::Git is the git implementation for \s-1VCI\s0, a generic interface to version-control systems. .PP Other Perl Git Wrappers is a list of other Git interfaces in Perl. If Git::Wrapper doesn't scratch your itch, possibly one of the modules listed there will. .PP Git itself is at . .SH "REPORTING BUGS & OTHER WAYS TO CONTRIBUTE" .IX Header "REPORTING BUGS & OTHER WAYS TO CONTRIBUTE" The code for this module is maintained on GitHub, at . If you have a patch, feel free to fork the repository and submit a pull request. If you find a bug, please open an issue on the project at GitHub. (We also watch the queue for Git::Wrapper, so feel free to use that bug reporting system if you prefer) .SH "AUTHORS" .IX Header "AUTHORS" .IP "\(bu" 4 Hans Dieter Pearcey .IP "\(bu" 4 Chris Prather .IP "\(bu" 4 John \s-1SJ\s0 Anderson .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2014 by Hans Dieter Pearcey. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.