Skip to content

Instantly share code, notes, and snippets.

@ssinyagin
Last active November 29, 2016 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssinyagin/5f6141c6979bcda4835d796a21858e12 to your computer and use it in GitHub Desktop.
Save ssinyagin/5f6141c6979bcda4835d796a21858e12 to your computer and use it in GitHub Desktop.
Working with Git::Raw (libgit2)
use strict;
use warnings;
use Git::Raw;
use IO::File;
use Data::Dumper;
my $dir = '/opt/t3/t/repo';
my $repo = Git::Raw::Repository->init($dir, 0);
print "OK\n";
my $remote =
Git::Raw::Remote->create($repo, 'origin', 'file:///tmp/xxx');
print "OK\n";
#my $fh = IO::File->new($dir . '/xx', 'w');
#$fh->close;
my $index = $repo->index;
#$index->add ('xx');
$index->write;
my $tree = $index->write_tree;
my $me = Git::Raw::Signature->now('Z', 'x@x.com');
$repo->commit('dada', $me, $me, [], $tree);
print "OK commit\n";
my $branch = Git::Raw::Branch->lookup( $repo, 'master', 1 );
$branch->move('xxxzzz', 1);
print "OK\n";
print $repo->head->target->id;
print "\n";
$remote->push(['refs/heads/xxxzzz:refs/heads/gdgdga']);
print "OK push\n";
$branch = Git::Raw::Branch->lookup( $repo, 'xxxzzz', 1 );
my $ref = Git::Raw::Reference->lookup('refs/remotes/origin/gdgdga', $repo);
$branch->upstream($ref);
print "OK upstr\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment