diff options
author | Sitaram Chamarty <sitaram@atc.tcs.com> | 2012-02-25 15:09:01 +0530 |
---|---|---|
committer | Sitaram Chamarty <sitaram@atc.tcs.com> | 2012-03-24 16:15:33 +0530 |
commit | 233a33deff06dc4d4cb41aedd67dadfa4a2bc2ea (patch) | |
tree | c91c8b13c895dec727a616894959b3c76cf7e6e6 | |
parent | (oopsies!) minor bug in a hurriedly written one-liner (diff) | |
download | gitolite-gentoo-233a33deff06dc4d4cb41aedd67dadfa4a2bc2ea.tar.gz gitolite-gentoo-233a33deff06dc4d4cb41aedd67dadfa4a2bc2ea.tar.bz2 gitolite-gentoo-233a33deff06dc4d4cb41aedd67dadfa4a2bc2ea.zip |
mirroring: fix several minor issues related to 'reponame.git'
- git prepends a '/' when people use the full form of an ssh URL.
Since I *never* use those, (I prefer setting an ssh host alias and
just saying 'git95:gitolite' for example), I never caught this.
- people will also append a '.git'. It's supposed to work either way,
but it wasn't. I had missed a few places where the user might send
in 'reponame.git' and was implicitly assuming it would be 'reponame'
- finally, we slip-streamed in a wrapper for system()
Big thanks and kudos to Michael Brown for catching these issues, and
(hopefully, heh!) testing my fixes ;-)
-rw-r--r-- | src/gitolite.pm | 13 | ||||
-rwxr-xr-x | src/gl-mirror-push | 1 | ||||
-rwxr-xr-x | src/gl-mirror-shell | 7 |
3 files changed, 20 insertions, 1 deletions
diff --git a/src/gitolite.pm b/src/gitolite.pm index 8120526..fbae91d 100644 --- a/src/gitolite.pm +++ b/src/gitolite.pm @@ -132,6 +132,19 @@ sub wrap_print { chmod $oldmode, $file if $oldmode; } +sub wrap_system { + system(@_); + + # straight from 'perldoc -f system' (sans the coredump part) + if ( $? == -1 ) { + print STDERR "failed to execute: $!\n"; + } elsif ( $? & 127 ) { + printf STDERR "child died with signal %d\n", ( $? & 127 ); + } else { + printf STDERR "child exited with value %d\n", $? >> 8; + } +} + sub slurp { local $/ = undef; my $fh = wrap_open("<", $_[0]); diff --git a/src/gl-mirror-push b/src/gl-mirror-push index 70514cb..e7054e2 100755 --- a/src/gl-mirror-push +++ b/src/gl-mirror-push @@ -25,6 +25,7 @@ hn=`get_rc_val GL_HOSTNAME` # get repo name then check if it's a local or slave (ie we're not the master) [ -z "$1" ] && die fatal: missing reponame argument repo=$1; shift +repo=${repo%.git} REPO_BASE=`get_rc_val REPO_BASE` cd $REPO_BASE/$repo.git 2>/dev/null || die fatal: could not change directory to "$repo" diff --git a/src/gl-mirror-shell b/src/gl-mirror-shell index e6b25c6..80534dc 100755 --- a/src/gl-mirror-shell +++ b/src/gl-mirror-shell @@ -52,6 +52,7 @@ critical for you to just run it based on a 'usage' message.\n" if not @ARGV or $ if ( ($ARGV[0] || '') eq 'request-push' and not $ENV{SSH_ORIGINAL_COMMAND} ) { shift; my $repo = shift or die "fatal: missing reponame\n"; + $repo =~ s/\.git$//; -d "$REPO_BASE/$repo.git" or die "fatal: no such repo?\n"; # this is the default argument if no slave list or key is supplied @@ -110,6 +111,7 @@ if ($soc eq 'info') { if ($soc =~ /^git-receive-pack '(\S+)'$/) { my $repo = $1; + $repo =~ s/\.git$//; die "fatal: invalid characters in $repo\n" unless $repo =~ $REPONAME_PATT; my $mm = mirror_mode($repo); @@ -137,11 +139,12 @@ if ($soc =~ /^git-receive-pack '(\S+)'$/) { if ($soc =~ /^request-push (\S+)$/) { my $repo = $1; + $repo =~ s/\.git$//; die "fatal: invalid characters in $repo\n" unless $repo =~ $REPONAME_PATT; die "$ABRT fatal: $GL_HOSTNAME ==//==> $sender refused: not in slave list\n" unless mirror_listslaves($repo) =~ /(^|\s)$sender(\s|$)/; print STDERR "$GL_HOSTNAME ==== ($repo) ===> $sender\n"; # just one sender, and we've checked that he is "on the list". Foreground... - system("$ENV{GL_BINDIR}/gl-mirror-push", $repo, "-fg", $sender); + wrap_system("$ENV{GL_BINDIR}/gl-mirror-push", $repo, "-fg", $sender); exit; } @@ -159,6 +162,8 @@ if ($soc =~ /^USER=(\S+) SOC=(git-receive-pack '(\S+)')$/) { my $user = $1; $ENV{SSH_ORIGINAL_COMMAND} = $2; my $repo = $3; + $repo =~ s/\.git$//; + $repo =~ s(^/)(); die "fatal: invalid characters in $user\n" unless $user =~ $USERNAME_PATT; die "fatal: invalid characters in $repo\n" unless $repo =~ $REPONAME_PATT; die "$ABRT fatal: $GL_HOSTNAME <==//== $sender redirected push rejected\n" unless mirror_redirectOK($repo, $sender); |