Skip to content

Commit

Permalink
- Added Git support in VC
Browse files Browse the repository at this point in the history
- Fixed documentation mentioning deprecated tagformat instead of tagpattern
  • Loading branch information
yannk committed Dec 9, 2007
1 parent bd43f68 commit f74c978
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS
@@ -1,2 +1,3 @@
Brad Fitzpatrick
Tatsuhiko Miyagawa
Yann Kerhervé (Git VC)
3 changes: 3 additions & 0 deletions ChangeLog
@@ -1,3 +1,6 @@
0.52 () XXX
* Added VC::Git (Yann)

0.51 (2006-06-18)

* Fixed VC::SVK to work with absolute path in tagpattern (Kang-Min Liu)
Expand Down
2 changes: 1 addition & 1 deletion lib/ShipIt/Step/FindVersion.pm
Expand Up @@ -23,7 +23,7 @@ sub run {

# are they just compulsively running shipit? i.e., they just asked for same
# version as something tagged & no local diffs....
if ($is_tagged && $newver eq $ver && ! $state->vc->are_local_diffs) {
if ($is_tagged && $newver eq $ver && ! $state->vc->are_local_diffs($ver)) {
die "No local changes, and version on disk is already tagged. Nothing to do.\n";
}

Expand Down
2 changes: 2 additions & 0 deletions lib/ShipIt/VC.pm
Expand Up @@ -2,6 +2,7 @@ package ShipIt::VC;
use strict;
use ShipIt::VC::SVN;
use ShipIt::VC::SVK;
use ShipIt::VC::Git;

=head1 NAME
Expand Down Expand Up @@ -36,6 +37,7 @@ memoized (er, singleton) instance of ShipIt::VC->new.
sub new {
my ($class, $conf) = @_;
return ShipIt::VC::SVN->new($conf) if -e ".svn";
return ShipIt::VC::Git->new($conf) if -e ".git";
return ShipIt::VC::SVK->new($conf) if $class->is_svk_co;
die "Unknown/undetected version control system. Currently only svn/svk is supported.";
}
Expand Down
106 changes: 106 additions & 0 deletions lib/ShipIt/VC/Git.pm
@@ -0,0 +1,106 @@
package ShipIt::VC::Git;
use strict;
use base 'ShipIt::VC';
use File::Temp ();

sub command { 'git' }

sub new {
my ($class, $conf) = @_;
my $self = bless {}, $class;
$self->{tagpattern} = $conf->value( $self->command . ".tagpattern" );
$self->{push_to} = $conf->value( $self->command . ".push_to" );
return $self;
}

=head1 NAME
ShipIt::VC::Git -- ShipIt's git support
=head1 CONFIGURATION
In your .shipit configuration file, the following options are recognized:
=over
=item B<git.tagpattern>
Defines how the tag are defined in your git repo.
=item B<git.push_to>
If you want the newly created to be pushed elsewhere (for instance in your
public git repository), then you can specify the destination in this variable
=back
=cut

sub exists_tagged_version {
my ($self, $ver) = @_;

my $command = $self->command;
my $x = `git tag -l $ver`;
chomp $x;
return $x;
}

sub commit {
my ($self, $msg) = @_;

my $command = $self->command;

if ( my $unk = `git ls-files -z --others --exclude-per-directory=.gitignore --exclude-from=.git/info/exclude` ) {
$unk =~ s/\0/\n/;
die "Unknown local files:\n$unk\n\nUpdate .gitignore, or $command add them";
exit(1);
}

# commit
my $tmp_fh = File::Temp->new(UNLINK => 1, SUFFIX => '.msg');
print $tmp_fh $msg;
my $tmp_fn = "$tmp_fh";
system($command, "commit", "-a", "-F", $tmp_fn);
}

sub local_diff {
my ($self, $file) = @_;
my $command = $self->command;
return `$command diff --no-color HEAD $file`;
}

sub _tag_of_version {
my ($self, $ver) = @_;
my $tag = $self->{tagpattern} || '';
$tag .= "%v" unless $tag =~ /\%v/i;
$tag =~ s/\%v/$ver/ig;
return $tag;
}

sub tag_version {
my ($self, $ver, $msg) = @_;
$msg ||= "Tagging version $ver.\n";
my $tmp_fh = File::Temp->new(UNLINK => 1, SUFFIX => '.msg');
print $tmp_fh $msg;
my $tmp_fn = "$tmp_fh";
my $tag = $self->_tag_of_version($ver);
## not GPG signed
system($self->command, "tag", "-a", "-F", $tmp_fn, $tag)
and die "Tagging of version '$ver' failed.\n";

if (my $where = $self->{push_to}) {
warn "pushing to $where";
system($self->command, "push", $where, tag => $tag);
}
}

sub are_local_diffs {
my ($self, $ver) = @_;
my $command = $self->command;
my $diff = `$command diff --no-color $ver`;
return $diff =~ /\S/ ? 1 : 0;
}

1;


2 changes: 1 addition & 1 deletion lib/ShipIt/VC/SVK.pm
Expand Up @@ -33,7 +33,7 @@ In your .shipit configuration file, the following options are recognized:
=over
=item B<svk.tagformat>
=item B<svk.tagpattern>
A pattern which ultimately expands into the absolute subversion URL for a tagged version. If the pattern isn't already absolute, the conventional "tags" directory is used as a base. The pattern has one magic variable, %v, which expands to the version number being tagged. If no %v is found, it's placed at the end.
Expand Down
2 changes: 1 addition & 1 deletion lib/ShipIt/VC/SVN.pm
Expand Up @@ -36,7 +36,7 @@ In your .shipit configuration file, the following options are recognized:
=over
=item B<svn.tagformat>
=item B<svn.tagpattern>
A pattern which ultimately expands into the absolute subversion URL for a tagged version. If the pattern isn't already absolute, the conventional "tags" directory is used as a base. The pattern has one magic variable, %v, which expands to the version number being tagged. If no %v is found, it's placed at the end.
Expand Down

0 comments on commit f74c978

Please sign in to comment.