Git Product home page Git Product logo

Comments (9)

jacquesg avatar jacquesg commented on May 27, 2024 1

There is some support, https://metacpan.org/pod/Git::Raw::Repository#revparse(-$spec-)

from p5-git-raw.

jacquesg avatar jacquesg commented on May 27, 2024 1

Use discover instead of open.

from p5-git-raw.

jacquesg avatar jacquesg commented on May 27, 2024 1

Check out the Git::Raw::Branch documentation. It has lookup, upstream_name and maybe remote_name which I think would be of use here.

Also, $repo->head should give you a Git::Raw::Reference for HEAD, which has name etc.

from p5-git-raw.

jacquesg avatar jacquesg commented on May 27, 2024

Have a look at t/25-revparse.t for usage examples.

from p5-git-raw.

waterkip avatar waterkip commented on May 27, 2024

I see, I was looking for in particular for these two:

rev-parse --abbrev-ref HEAD
rev-parse --show-toplevel

from p5-git-raw.

jacquesg avatar jacquesg commented on May 27, 2024

libgit2 and Git::Raw provide building blocks to implement these yourself.

rev-parse --show-toplevel I think is as simple as calling $repo->workdir.
rev-parse --abbrev-ref HEAD I think could be implemented by calling Git::Raw::Commit->lookup ($repo, $id) where you chop off characters until you get an error? Would expect it to be a Git::Raw::Error->EAMBIGUOUS

from p5-git-raw.

waterkip avatar waterkip commented on May 27, 2024

The first one doesn't work when you aren't in the top of your working dir:

$ cat t/foo.pl
#!/usr/bin/perl
use warnings;
use strict;
use Git::Raw::Repository;
use Cwd qw(cwd);
my $repo = Git::Raw::Repository->open(cwd());
print $repo->workdir, $/;
14:10 pts/3 0 wesleys@neptune:/home/wesleys/code/git-repo
$ perl t/foo.pl
/home/wesleys/code/git-repo/
14:10 pts/3 0 wesleys@neptune:/home/wesleys/code/git-repo
$ cd t
14:10 pts/3 0 wesleys@neptune:/home/wesleys/code/git-repo/t
$ perl foo.pl
could not find repository from '/home/wesleys/code/git-repo/t' at foo.pl line 814:11 pts/3 2 wesleys@neptune:/home/wesleys/code/git-repo/t
$

from p5-git-raw.

waterkip avatar waterkip commented on May 27, 2024

That works! Thanks.

The latter command spits out the branch you are in, and I also want something that returns the tracking branch which I do with git rev-parse --abbrev-ref @{u}

from p5-git-raw.

waterkip avatar waterkip commented on May 27, 2024

Will do!

from p5-git-raw.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.