RemoteForward 9001 localhost:9001
+bak command overview:
+
+ bak add /path
+ bak commit [/path [message]]
+ bak diff
+ bak status
+ bak log
+
+ bak ch[anges]
+ bak revert /path
+
+ bak - push all changed files to server
+
=cut
use warnings;
}
while (my $client = $server->accept()) {
- my ($hostname,$pwd,$command,$rel_path,$message) = split(/\s+/,<$client>,5);
+ my $line = <$client>;
+ warn "<<< $line\n";
+ my ($hostname,$pwd,$command,$rel_path,$message) = split(/\s+/,$line,5);
my $path = $rel_path =~ m{^/} ? $rel_path : "$pwd/$rel_path";
my $dir = $path;
$dir =~ s{/[^/]+$}{};
+ sub git {
+ my $args = join(' ',@_);
+ warn "# git $args\n";
+ my $out = `git $args`;
+ warn "$out\n# [", length($out), " bytes]\n" if defined $out;
+ return $out;
+ }
+
if ( ! $command ) {
pull_changes $hostname;
} elsif ( $command eq 'add' ) {
mkpath "$hostname/$dir" unless -e "$hostname/$dir";
system 'rsync', '-avv', "root\@$hostname:$path", "$hostname/$path";
- system 'git', 'add', "$hostname/$path";
+ print $client git 'add', "$hostname/$path";
} elsif ( $command eq 'commit' ) {
pull_changes $hostname;
- system 'git', 'commit', '-m', $message,
- -e "$hostname/$path" ? "$hostname/$path" : $hostname;
- } elsif ( $command =~ m{(diff|status|log)} ) {
- my $opt = '--summary' if $command eq 'log';
+ $message =~ s/'/\\'/g;
+ print $client git( "commit -m '$message' ",
+ ( -e "$hostname/$path" ? "$hostname/$path" : $hostname )
+ );
+ } elsif ( $command =~ m{(diff|status|log|ch)} ) {
+ $command .= ' --stat' if $command eq 'log';
+ $command = 'log --patch-with-stat' if $command =~ m/^ch/;
pull_changes $hostname if $command eq 'diff';
- print $client `git $command $opt $hostname`;
+ print $client git($command,$hostname);
} elsif ( $command eq 'revert' ) {
- print $client `git checkout -- $hostname/$path`;
+ print $client git "checkout -- $hostname/$path";
system 'rsync', '-avv', "$hostname/$path", "root\@$hostname:$path";
} else {
print $client "Unknown command: $command\n";