~ubuntu-branches/ubuntu/utopic/gitolite3/utopic-proposed

« back to all changes in this revision

Viewing changes to src/lib/Gitolite/Triggers/Alias.pm

  • Committer: Package Import Robot
  • Author(s): David Bremner
  • Date: 2013-05-18 17:59:21 UTC
  • Revision ID: package-import@ubuntu.com-20130518175921-ac4xe6vd0jtxvjot
Tags: upstream-3.5.1+4
ImportĀ upstreamĀ versionĀ 3.5.1+4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package Gitolite::Triggers::Alias;
 
2
 
 
3
use Gitolite::Rc;
 
4
use Gitolite::Common;
 
5
use Gitolite::Conf::Load;
 
6
 
 
7
use strict;
 
8
use warnings;
 
9
 
 
10
# aliasing a repo to another
 
11
# ----------------------------------------------------------------------
 
12
 
 
13
=for usage
 
14
 
 
15
Why:
 
16
 
 
17
    We had an existing repo "foo" that lots of people use.  We wanted to
 
18
    rename it to "foo/code", so that related repos "foo/upstream" and
 
19
    "foo/docs" (both containing stuff we did not want to put in "foo") could
 
20
    also be made and then the whole thing would be structured nicely.
 
21
 
 
22
    At the same time we did not want to *force* all the users to change the
 
23
    name.  At least git operations should still work with the old name,
 
24
    although it is OK for "info" and other "commands" to display/require the
 
25
    proper name (i.e., the new name).
 
26
 
 
27
How:
 
28
 
 
29
  * add a new variable REPO_ALIASES to the rc file, with entries like:
 
30
 
 
31
        REPO_ALIASES                =>
 
32
            {
 
33
                'foo'               =>  'foo/code',
 
34
            }
 
35
 
 
36
  * add the following line to the INPUT section in the rc file:
 
37
 
 
38
        'Alias::input',
 
39
 
 
40
Notes:
 
41
 
 
42
  * only git operations (clone/fetch/push) are alias aware.  Nothing else in
 
43
    gitolite, such as all the gitolite commands etc., are alias-aware and will
 
44
    always use/require the proper repo name.
 
45
 
 
46
  * http mode has not been tested and will not be.  If someone has the time to
 
47
    test it and make it work please let me know.
 
48
 
 
49
  * funnily enough, this even works with mirroring!  That is, a master can
 
50
    push a repo "foo" to a slave per its configuration, while the slave thinks
 
51
    it is getting repo "bar" from the master per its configuration.
 
52
 
 
53
    Just make sure to put the Alias::input line *before* the Mirroring::input
 
54
    line in the rc file on the slave.
 
55
 
 
56
    However, it will probably not work with redirected pushes unless you setup
 
57
    the opposite alias ("bar" -> "foo") on master.
 
58
=cut
 
59
 
 
60
sub input {
 
61
    my $git_commands = "git-upload-pack|git-receive-pack|git-upload-archive";
 
62
    my $user = $ARGV[0] || '@all';    # user name is undocumented for now
 
63
 
 
64
    if ( $ENV{SSH_ORIGINAL_COMMAND} =~ /(?:$git_commands) '\/?(\S+)'$/ ) {
 
65
        my $repo = $1;
 
66
        ( my $norm = $repo ) =~ s/\.git$//;    # normalised repo name
 
67
 
 
68
        my $target;
 
69
 
 
70
        return unless $target = $rc{REPO_ALIASES}{$norm};
 
71
        $target = $target->{$user} if ref($target) eq 'HASH';
 
72
        return unless $target;
 
73
 
 
74
        _warn "'$norm' is an alias for '$target'";
 
75
 
 
76
        $ENV{SSH_ORIGINAL_COMMAND} =~ s/'\/?$repo'/'$target'/;
 
77
    }
 
78
 
 
79
}
 
80
 
 
81
1;