1 package Config::GitLike::Git;
6 extends 'Config::GitLike';
9 default => 'gitconfig',
18 my $path = File::Spec->rel2abs( shift );
21 ($path) = grep {-d} map {"$path$_"} (".git/.git", "/.git", ".git", "");
24 # Has to have objects/ and refs/ directories
25 return unless -d "$path/objects" and -d "$path/refs";
27 # Has to have a HEAD file
28 return unless -f "$path/HEAD";
30 if (-l "$path/HEAD" ) {
31 # Symbolic link into refs/
32 return unless readlink("$path/HEAD") =~ m{^refs/};
34 open(HEAD, "$path/HEAD") or return;
37 # Is either 'ref: refs/whatever' or a sha1
38 return unless $line =~ m{^(ref:\s*refs/|[0-9a-fA-F]{20})};
46 my $dir = $self->is_git_dir($path) or return;
47 $self->load_file( File::Spec->catfile( $dir, "config" ) );
50 __PACKAGE__->meta->make_immutable;
59 Config::GitLike::Git - load Git configuration files
63 use Config::GitLike::Git;
64 my $config = Config::GitLike::Git->new;
65 $config->load("/path/to/repo");
69 This is a modification of L<Config::GitLike> to look at the same
70 locations that Git writes to. Unlike with L<Config::GitLike>, you do
71 not need to pass a confname to its constructor. This module also
72 enables the L<Config::GitLike> option to maintain git compatibility
73 when reading and writing variables.
75 L<Config::GitLike/load> should be passed path to the top level of a
76 git repository -- this defaults to the current directory. It will
77 append C<.git> as necessary. It supports both bare and non-bare
82 This module overrides these methods from C<Config::GitLike>:
86 The per-directory configuration file is F<.git/config>
90 The per-user configuration file is F<~/.gitconfig>
94 The per-host configuration file is F</etc/gitconfig>
98 L<Config::GitLike|Config::GitLike>
102 You may modify and/or redistribute this software under the same terms
107 Copyright 2010 Best Practical Solutions, LLC
111 Alex Vandiver <alexmv@bestpractical.com>,
112 Christine Spang <spang@bestpractical.com>