Skip to content
Handy shortcuts for common git commands
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
lib/Git increment $VERSION after 0.000018 release Feb 8, 2019
script Add version numbers to delete-git-branches script Feb 8, 2019
t
.gitignore
.perltidyrc Initial commit. Apr 18, 2015
.stopwords
.tidyallrc
.travis.yml
Changes
Install Adds Install and META.json files. Jan 12, 2017
LICENSE v0.000014 Mar 23, 2018
META.json
Makefile.PL increment $VERSION after 0.000018 release Feb 8, 2019
README.md
cpanfile v0.000018 Feb 8, 2019
dist.ini
perlcriticrc Adds some files created by dzil. Jul 28, 2016
perltidyrc
tidyall.ini

README.md

NAME

Git::Helpers - Shortcuts for common Git commands

Build Status

VERSION

version 0.000018

SYNOPSIS

use Git::Helpers qw(
    checkout_root
    current_branch_name
    https_remote_url
    is_inside_work_tree
    remote_url
    travis_url
);

my $dir              = '/path/to/folder/in/git/checkout';
my $root             = checkout_root($dir);
my $current_branch   = current_branch_name();
my $https_remote_url = https_remote_url();
my $inside_work_tree = is_inside_work_tree();
my $remote_url       = remote_url('upstream');
my $travis_url       = travis_url();

checkout_root( $dir )

Gives you the root level of the git checkout which you are currently in. Optionally accepts a directory parameter. If you provide the directory parameter, checkout_root will temporarily chdir to this directory and find the top level of the repository.

This method will throw an exception if it cannot find a git repository at the directory provided.

current_branch_name

Returns the name of the current branch.

https_remote_url( $remote_name, $use_current_branch )

This is a browser-friendly URL for the remote, fixed up in such a way that GitHub (hopefully) doesn't need to redirect your URL.

Turns git@github.com:oalders/git-helpers.git into https://github.com/oalders/git-helpers

Turns https://github.com/oalders/git-helpers.git into https://github.com/oalders/git-helpers

Defaults to using origin as the remote if none is supplied.

Defaults to master branch, but can also display current branch.

my $current_branch_url = https_remote_url( 'origin', 1 );

ignored_files( $dir )

Returns an arrayref of files which exist in your checkout, but are ignored by Git. Optionally accepts a directory as an argument. Defaults to ".".

Throws an exception if there has been an error running the command.

is_inside_work_tree

Returns true if git rev-parse --is-inside-work-tree returns true. Otherwise returns false. This differs slightly from the behaviour of --is-inside-work-tree in real life, since it returns fatal rather than false if run outside of a git repository.

remote_url( $remote_name )

Returns a URL for the remote you've requested by name. Defaults to 'origin'. Provides you with the exact URL which git returns. Nothing is fixed up for you.

# defaults to 'origin'
my $remote_url = remote_url();
# $remote_url is now possibly something like one of the following:
# git@github.com:oalders/git-helpers.git
# https://github.com/oalders/git-helpers.git

# get URL for upstream remote
my $upstream_url = remote_url('upstream');

travis_url( $remote_name )

Returns a travis-ci.org URL for the remote you've requested by name. Defaults to 'origin'.

# get Travis URL for remote named "origin"
my $origin_travis_url = travis_url();

# get Travis URL for remote named "upstream"
my $upstream_travis_url = travis_url('upstream');

AUTHOR

Olaf Alders olaf@wundercounter.com

COPYRIGHT AND LICENSE

This software is copyright (c) 2015-2018 by Olaf Alders.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

You can’t perform that action at this time.