[Bps-public-commit] git-sync branch, master, updated. a448abe5de8950a780785c82b702864e3883687d

Alex M Vandiver alexmv at bestpractical.com
Sat Nov 21 22:51:16 EST 2009


The branch, master has been updated
       via  a448abe5de8950a780785c82b702864e3883687d (commit)
       via  e7c5ea52b3965ea90c78d8d64db993e5abbe1820 (commit)
       via  22539bd56a8b2ab586c4544a18423998ed5ba8cc (commit)
       via  679884223be1aee566162429a61ef6313e17f5bc (commit)
       via  02979c457549de0a8b333edd7e451de5699b38f0 (commit)
       via  eb735c239bedcbf487e56fb9a102971a1e1ee2d1 (commit)
      from  33b01fa7f98b27ae4ae1add8394919529d08fcfe (commit)

Summary of changes:
 git-sync |  187 +++++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 155 insertions(+), 32 deletions(-)

- Log -----------------------------------------------------------------
commit eb735c239bedcbf487e56fb9a102971a1e1ee2d1
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat Nov 21 22:43:06 2009 -0500

    Detect remote categories by presence of "host" parameter

diff --git a/git-sync b/git-sync
index 53f68c9..b090c0d 100755
--- a/git-sync
+++ b/git-sync
@@ -55,12 +55,12 @@ for my $name (@categories) {
 
     if (not $sync{$name}{into}) {
         print colored("  No 'into' set, skipping!\n", "red");
-    } elsif (exists $sync{$name}{local}) {
-        sync_all_local(%{$sync{$name}});
+    } elsif (exists $sync{$name}{host}) {
+        sync_all_remote(%{$sync{$name}});
     } elsif (exists $sync{$name}{github}) {
         sync_all_github(%{$sync{$name}});
     } else {
-        sync_all_remote(%{$sync{$name}});
+        sync_all_local(%{$sync{$name}});
     }
     print " "x45,"\n";
 }

commit 02979c457549de0a8b333edd7e451de5699b38f0
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat Nov 21 22:44:29 2009 -0500

    "Host" will always be set here now

diff --git a/git-sync b/git-sync
index b090c0d..6333d56 100755
--- a/git-sync
+++ b/git-sync
@@ -129,9 +129,6 @@ sub sync_all_github {
 sub sync_all_remote {
     my %config = @_;
 
-    print colored("  No 'host' set, skipping!\n", "red") and return
-        unless $config{host};
-
     print colored("  No 'path' set, skipping!\n", "red") and return
         unless $config{path};
 

commit 679884223be1aee566162429a61ef6313e17f5bc
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat Nov 21 22:45:16 2009 -0500

    Allow `host = example.com:/path/to/dir`

diff --git a/git-sync b/git-sync
index 6333d56..94a59f9 100755
--- a/git-sync
+++ b/git-sync
@@ -129,6 +129,8 @@ sub sync_all_github {
 sub sync_all_remote {
     my %config = @_;
 
+    @config{qw/host path/} = ($1, $2) if $config{host} =~ /^(.*?):(.*)/;
+
     print colored("  No 'path' set, skipping!\n", "red") and return
         unless $config{path};
 

commit 22539bd56a8b2ab586c4544a18423998ed5ba8cc
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat Nov 21 22:46:27 2009 -0500

    Add POD, --help option to show it

diff --git a/git-sync b/git-sync
index 94a59f9..2029b11 100755
--- a/git-sync
+++ b/git-sync
@@ -1,20 +1,154 @@
 #!/usr/bin/env perl
 
-# Simple usage:
-# add the config found after __END__ to your config
-# the script will search like git does, so
-# ./.git/config, ~/.gitconfig, /etc/gitconfig
-#
-# $ git sync
-# syncs all sync sections of your config
-# $ git sync bps
-# syncs only one of the sections
+=head1 NAME
+
+git-sync - synchronize multiple git repositories
+
+=head1 SYNOPSIS
+
+    git-sync [--verbose] [--dry-run] [--log] [category]
+
+=head1 DESCRIPTION
+
+C<git-sync> is a tool to keep multiple git repositories up-to-date
+with their upstream repositories, and to clone new repositories as
+they are added to the upstream location.
+
+The updating is done in a manner which preserves your local state, and
+I<should> not cause conflicts.  A C<git remote update --prune> is always done;
+if the user has no uncommitted changes, and the merge would be a
+fast-forward, the current branch is C<git pull>ed, and the diffstat is
+printed.  Otherwise, the state of the repository is shown in a concise
+manner.
+
+C<git-sync> also understands C<git-svn> clones, and updates them using
+the same rules, but using C<git svn fetch> and C<git svn rebase>
+instead of C<git remote update> and C<git pull>.
+
+There are three configuration modes:
+
+=over
+
+=item Local
+
+All of the repositories in a local directory (or set of directories)
+are updated as above.  If any of these directories overlap with
+L</Github> or L</Remote> directories, the repositories are only
+updated once.
+
+=item Github
+
+All of a specific user's repositories (or set of users' repositories)
+from Github are cloned into a specified directory.  By default, a
+writable clone via the SSH is attempted; if this fails, C<git-sync>
+falls back to the read-only C<git> protocol.  If a clone already
+exists, it is updated as above.
+
+=item Remote
+
+All of the repositories in a specific directory (or set of
+directories) on a remote (SSH) server are cloned into a specified
+directory.  If a clone already exists, it is updated as above.
+
+C<git-sync> attempts to make use of SSH master connections to speed up
+clone and update attempts; see C<ControlPath> and C<ControlMaster> in
+L<ssh_config>.  A common configuration might be:
+
+    Host githost.example.com
+    ControlMaster auto
+    ControlPath /home/alexmv/.ssh/master-%r@%h:%p
+
+=back
+
+=head1 CONFIGURATION
+
+Configuration is done through C<git config> files (F<~/.gitconfig> and
+the like).  C<sync.I<category>> sections define common synchronization
+categories.  The C<into> key is required; it specifies the local path
+where repositories will be found or placed.
+
+    [sync "a-local-dir"]
+            # All git repositories directly underneath this one will
+            # be updated
+            into = /home/alexmv/hacking
+
+If a C<github> key is provided, all repositories of that user (or
+users) are cloned and updated:
+
+    [sync "a-github-account"]
+            # The "github" key makes this category github-based
+            github = alexmv
+            github = bestpractical
+            # All of alexmv's and bestpractical's repositories will be
+            # cloned and updated under this directory
+            into = /home/alexmv/github
+
+The presence of C<host> and C<path> keys configures a remote directory
+to clone from.  Multiple values for C<path> can be given; alternately,
+if only one path is needed, C<host> can be specified as
+C<hostname:/path>.
+
+    [sync "a-remote-dir"]
+            # The "host" key makes this category remote-server based
+            host = example.com:/git
+            # All repositories under /git will be cloned and updated
+            # under this directory
+            into = /home/alexmv/example.com
+
+Note that local categories can be overlapped with other types; the
+following configuration clones and updates all of alexmv's github
+repositories, and also updates any other repositories it happens to
+find in C</home/alexmv/github>:
+
+    [sync "local"]
+            into = /home/alexmv/github
+    [sync "github"]
+            github = alexmv
+            into = /home/alexmv/github
+
+Remote and Github configurations also support the C<email> key; if set,
+newly-cloned repositories will have C<user.email> set to the given
+value.
+
+=head1 OPTIONS
+
+=over
+
+=item C<--verbose> or C<-v>
+
+Be more verbose about which repositories are skipped, and why.
+
+=item C<--pretend> or C<--dry-run>
+
+Remote repositories are not fetched from; the list of repositories
+that would be synchronized is listed, and their state.  Note that
+network access is still needed to obtain a list of repositories for
+L</Github> and L</Remote> directories.
+
+=item C<--log> or C<-l>
+
+When a repository is ahead or behind its tracking remote (but not
+diverged), show the output of C<git log --oneline --reverse> for the
+list of commits that differ.
+
+=item C<--help> or C<-h>
+
+Shows this documentation.
+
+=back
+
+Other parameters passed on the command line are taken to be categories
+to be synchronized; if no other arguments are given, synchronzies all
+categories.
+
+=cut
 
 use Git;
 use strict;
 use warnings;
 use Term::ANSIColor;
 use Getopt::Long;
+use Pod::Usage;
 use LWP::Simple qw();
 use File::Path qw();
 
@@ -24,12 +158,14 @@ $SIG{INT} = sub {
 };
 $SIG{USR1} = 'IGNORE';
 
-my ($verbose, $pretend, $log);
+my ($verbose, $pretend, $log, $help);
 GetOptions(
     'verbose|v' => \$verbose,
     'pretend|dry-run' => \$pretend,
     'log|l' => \$log,
-);
+    'help|h' => \$help,
+) or pod2usage( -verbose => 1 );
+pod2usage( -verbose => 2 ) if $help;
 
 my %sync;
 for (split /\0/, `git config -z --get-regexp ^sync\\\\.`) {
@@ -336,17 +472,3 @@ sub logs {
     $logmsg =~ s/^(\S+)/"    ".colored($1,"yellow")/egm;
     return $logmsg;
 }
-
-__END__
-[sync "bps"]
-    host = fsck.com
-    path = /git
-    path = /git-private
-    into = /home/chmrr/work/bps/git
-    email = alexmv at bestpractical.com
-[sync "localrepos"]
-    into = /home/chmrr/gitprojects
-    local = true
-[sync "github"]
-    into = /home/chmrr/github
-    github = alexmv

commit e7c5ea52b3965ea90c78d8d64db993e5abbe1820
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat Nov 21 22:46:58 2009 -0500

    Add -n synonym for --dry-run

diff --git a/git-sync b/git-sync
index 2029b11..099049e 100755
--- a/git-sync
+++ b/git-sync
@@ -118,7 +118,7 @@ value.
 
 Be more verbose about which repositories are skipped, and why.
 
-=item C<--pretend> or C<--dry-run>
+=item C<--pretend> or C<--dry-run> or C<-n>
 
 Remote repositories are not fetched from; the list of repositories
 that would be synchronized is listed, and their state.  Note that
@@ -161,7 +161,7 @@ $SIG{USR1} = 'IGNORE';
 my ($verbose, $pretend, $log, $help);
 GetOptions(
     'verbose|v' => \$verbose,
-    'pretend|dry-run' => \$pretend,
+    'pretend|dry-run|n' => \$pretend,
     'log|l' => \$log,
     'help|h' => \$help,
 ) or pod2usage( -verbose => 1 );

commit a448abe5de8950a780785c82b702864e3883687d
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat Nov 21 22:51:13 2009 -0500

    Only use colored output if STDOUT is a TTY

diff --git a/git-sync b/git-sync
index 099049e..b2672b6 100755
--- a/git-sync
+++ b/git-sync
@@ -146,12 +146,14 @@ categories.
 use Git;
 use strict;
 use warnings;
-use Term::ANSIColor;
+use Term::ANSIColor qw//;
 use Getopt::Long;
 use Pod::Usage;
 use LWP::Simple qw();
 use File::Path qw();
 
+sub colored { (-t STDOUT) ? Term::ANSIColor::colored(@_) : $_[0] }
+
 $SIG{INT} = sub {
     print colored("\n\nInterrupted!\n", "bold red");
     exit;

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list