VCS: Git
+UseGit: 1
StatusStrict: 1
StatusOpenList: New
StatusOpenList: InProgress
$cil->read_config_user();
$cil->read_config_file();
- $cil->check_args($args);
# add any hooks we want
# none yet
The C<.cil> file is fairly simple and an example can be seen here:
- VCS: Git
+ UseGit: 1
StatusStrict: 1
StatusOpenList: New
StatusOpenList: InProgress
=over
-=item VCS
+=item UseGit
-Default: empty, Type: Enum(Git)
+Default: 0, Type: Boolean (0/1)
-Currently this option only supports Git. This enables you to use the 'track'
-command.
+Determines whether to use Git or not. Some features require Git though Cil is
+perfectly usable without.
=item StatusStrict
Summary: Remove the whole VCS.pm stuff, just have a Git.pm at the top level
-Status: New
+Status: Finished
CreatedBy: Andrew Chilton <andychilton@gmail.com>
AssignedTo: Andrew Chilton <andychilton@gmail.com>
Label: Milestone-v0.07
Inserted: 2010-01-24T10:17:18
-Updated: 2010-01-24T10:39:29
+Updated: 2010-01-25T09:55:05
No-one is going to use cil with anything other than Git (well, maybe not using
Git at all) so remove all the abstract stuff that isn't needed.
use Carp qw(croak confess);
use File::Glob qw(:glob);
use File::HomeDir;
-use Git;
+use CIL::Git;
use vars qw( $VERSION );
$VERSION = '0.5.1';
search_path => [ 'CIL::Command' ],
require => 1;
-use CIL::VCS::Factory;
-
use base qw(Class::Accessor);
__PACKAGE__->mk_accessors(qw(
IssueDir
StatusStrict StatusAllowed StatusOpen StatusClosed
LabelStrict LabelAllowed
DefaultNewStatus
- VCS
+ UseGit
UserName UserEmail
AutoAssignSelf
- vcs hook
- vcs_revision
+ git hook
));
my $defaults = {
StatusStrict => 0, # whether to complain if a status is invalid
LabelStrict => 0, # whether to complain if a label is invalid
DefaultNewStatus => 'New', # What Status to use for new issues by default
- VCS => 'Null', # don't do anything for VCS hooks
+ UseGit => 0, # don't do anything with Git
};
my @config_hashes = qw(StatusOpen StatusClosed LabelAllowed);
};
my $allowed = {
- vcs => {
- 'Git' => 1,
- },
hook => {
'issue_post_save' => 1,
},
return $self;
}
-#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
sub command_names {
return map { $_->name } $_[0]->commands;
}
-#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
sub list_entities {
my ($self, $prefix, $base) = @_;
$base = '' unless defined $base;
my $globpath = $self->IssueDir . "/${prefix}_${base}*.cil";
- my @filenames;
- if ( $self->vcs_revision ) {
- @filenames = $self->vcs->glob_rev($self->vcs_revision, $globpath);
- }
- else {
- @filenames = bsd_glob($globpath);
- }
+ my @filenames = bsd_glob($globpath);
my @entities;
foreach my $filename ( sort @filenames ) {
my $cfg;
if ( -f $filename ) {
$cfg = CIL::Utils->parse_cil_file( $filename );
+ %$cfg = (%$defaults, %$cfg);
}
else {
+ # set some defaults if we don't have a .cil file
$cfg = $defaults;
}
- # set some defaults if we don't have any of these
- %$cfg = (%$defaults, %$cfg);
-
# for some things, make a hash out of them
foreach my $hash_name ( @config_hashes ) {
# if we have nothing in the cfg hash already, set it to empty and move on
# set each config item
$self->IssueDir( $cfg->{IssueDir} );
+ $self->UseGit( $cfg->{UseGit} );
# Status info
$self->StatusStrict( $cfg->{StatusStrict} );
$self->DefaultNewStatus( $cfg->{DefaultNewStatus} );
- # if we are allowed this VCS, create the hook instance
- $self->VCS( $cfg->{VCS} || 'Null' );
- my $vcs = CIL::VCS::Factory->new( $cfg->{VCS} );
- $self->vcs( $vcs );
-}
-
-sub check_args {
- my ($self, $args) = @_;
-
- if ( $args->{r} ) {
- $self->vcs_revision($args->{r});
- if ( !$self->VCS or $self->VCS eq "Null" ) {
- warn "No VCS set in config file!\n";
- }
+ # create the git instance if we want it
+ $self->UseGit( $cfg->{UseGit} || 0 );
+ if ( $self->UseGit ) {
+ $self->git( CIL::Git->new() );
}
}
-
sub register_hook {
my ($self, $hook_name, $code) = @_;
sub file_exists {
my ($self, $filename) = @_;
- if ( $self->vcs_revision ) {
- $self->vcs->file_exists($self->vcs_revision, $filename);
- }
- else {
- -f $filename;
- }
+ return -f $filename;
}
sub dir_exists {
my ($self, $dir) = @_;
-
- return $self->vcs_revision
- ? $self->vcs->dir_exists($self->vcs_revision, $dir)
- : -d $dir
- ;
+ return -d $dir;
}
sub parse_cil_file {
my ($self, $filename, $last_field) = @_;
-
- if ( $self->vcs_revision ) {
- my $fh = $self->vcs->get_fh($self->vcs_revision, $filename);
- CIL::Utils->parse_from_fh($fh, $last_field);
- }
- else {
- CIL::Utils->parse_cil_file($filename, $last_field);
- }
+ return CIL::Utils->parse_cil_file($filename, $last_field);
}
sub save {
my ($self, $filename, $data, @fields) = @_;
-
- if ( $self->vcs_revision ) {
- confess "tried to ->save on alternate revision";
- }
- else {
- CIL::Utils->write_cil_file( $filename, $data, @fields );
- }
+ return CIL::Utils->write_cil_file( $filename, $data, @fields );
}
## ----------------------------------------------------------------------------
$issue = CIL::Utils->add_issue_loop($cil, undef, $issue);
- # if we want to add or commit this issue
- if ( $args->{add} or $args->{commit} ) {
- $cil->vcs->add( $cil, $issue );
- }
+ if ( $cil->UseGit ) {
+ # if we want to add or commit this issue
+ if ( $args->{add} or $args->{commit} ) {
+ $cil->git->add( $cil, $issue );
+ }
- # if we want to commit this issue
- if ( $args->{commit} ) {
- $cil->vcs->commit( $cil, 'New Issue', $issue );
+ # if we want to commit this issue
+ if ( $args->{commit} ) {
+ $cil->git->commit( $cil, 'New Issue', $issue );
+ }
}
}
$comment = CIL::Utils->add_comment_loop($cil, undef, $issue, $comment);
- # if we want to add or commit this comment
- if ( $args->{add} or $args->{commit} ) {
- $cil->vcs->add( $cil, $issue );
- $cil->vcs->add( $cil, $comment );
- }
-
- # if we want to commit this comment
- if ( $args->{commit} ) {
- $cil->vcs->commit( $cil, 'New Comment', $issue, $comment );
+ if ( $cil->UseGit ) {
+ # if we want to add or commit this comment
+ if ( $args->{add} or $args->{commit} ) {
+ $cil->git->add( $cil, $issue );
+ $cil->git->add( $cil, $comment );
+ }
+
+ # if we want to commit this comment
+ if ( $args->{commit} ) {
+ $cil->git->commit( $cil, 'New Comment', $issue, $comment );
+ }
}
}
$issue->save($cil);
$depends->save($cil);
- # if we want to add or commit this change
- if ( $args->{add} or $args->{commit} ) {
- $cil->vcs->add( $cil, $issue );
- $cil->vcs->add( $cil, $depends );
- }
-
- # if we want to commit this change
- if ( $args->{commit} ) {
- my $message = 'Issue ' . $issue->name . ' has a new dependent ' . $depends->name;
- $cil->vcs->commit_multiple( $cil, $message, $issue, $depends );
+ if ( $cil->UseGit ) {
+ # if we want to add or commit this change
+ if ( $args->{add} or $args->{commit} ) {
+ $cil->git->add( $cil, $issue );
+ $cil->git->add( $cil, $depends );
+ }
+
+ # if we want to commit this change
+ if ( $args->{commit} ) {
+ my $message = 'Issue ' . $issue->name . ' has a new dependent ' . $depends->name;
+ $cil->git->commit_multiple( $cil, $message, $issue, $depends );
+ }
}
}
# save it
$issue->save($cil);
- # if we want to add or commit this issue
- if ( $args->{add} or $args->{commit} ) {
- $cil->vcs->add( $cil, $issue );
- }
+ if ( $cil->UseGit ) {
+ # if we want to add or commit this issue
+ if ( $args->{add} or $args->{commit} ) {
+ $cil->git->add( $cil, $issue );
+ }
- # if we want to commit this issue
- if ( $args->{commit} ) {
- $cil->vcs->commit( $cil, 'Issue Edited', $issue );
+ # if we want to commit this issue
+ if ( $args->{commit} ) {
+ $cil->git->commit( $cil, 'Issue Edited', $issue );
+ }
}
CIL::Utils->display_issue($cil, $issue);
}
# are we in a Git repository?
- my $VCSconfig = '';
+ my $use_git = 0;
if ( -d '.git' ) {
- CIL::Utils->msg( 'git repository detected, setting VCS accordingly' );
- $VCSconfig = 'VCS: Git';
- my $vcs = CIL::VCS::Factory->new( 'Git' );
+ CIL::Utils->msg( 'git repository detected, setting to use it' );
+ $use_git = 1;
}
# create a .cil file here also
else {
# write a default .cil file
write_file($config, <<"CONFIG");
-$VCSconfig
+UseGit: $use_git
StatusStrict: 1
StatusOpenList: New
StatusOpenList: InProgress
# save
$issue->save($cil);
- # if we want to add or commit this issue
- if ( $args->{add} or $args->{commit} ) {
- $cil->vcs->add( $cil, $issue );
+ if ( $cil->UseGit ) {
+ # if we want to add or commit this issue
+ if ( $args->{add} or $args->{commit} ) {
+ $cil->git->add( $cil, $issue );
+ }
}
push @issues, $issue;
}
- # if we want to commit these issues
- if ( $args->{commit} ) {
- if ( $args->{remove} ) {
- $cil->vcs->commit_multiple( $cil, "Removed label '$label'", @issues );
- }
- else {
- $cil->vcs->commit_multiple( $cil, "Added label '$label'", @issues );
+ if ( $cil->UseGit ) {
+ # if we want to commit these issues
+ if ( $args->{commit} ) {
+ if ( $args->{remove} ) {
+ $cil->git->commit_multiple( $cil, "Removed label '$label'", @issues );
+ }
+ else {
+ $cil->git->commit_multiple( $cil, "Added label '$label'", @issues );
+ }
}
}
}
$issue->save($cil);
$precedes->save($cil);
- # if we want to add or commit this change
- if ( $args->{add} or $args->{commit} ) {
- $cil->vcs->add( $cil, $issue );
- $cil->vcs->add( $cil, $precedes );
- }
-
- # if we want to commit this change
- if ( $args->{commit} ) {
- my $message = 'Issue ' . $issue->name . ' precedes ' . $precedes->name;
- $cil->vcs->commit_multiple( $cil, $message, $issue, $precedes );
+ if ( $cil->UseGit ) {
+ # if we want to add or commit this change
+ if ( $args->{add} or $args->{commit} ) {
+ $cil->git->add( $cil, $issue );
+ $cil->git->add( $cil, $precedes );
+ }
+
+ # if we want to commit this change
+ if ( $args->{commit} ) {
+ my $message = 'Issue ' . $issue->name . ' precedes ' . $precedes->name;
+ $cil->git->commit_multiple( $cil, $message, $issue, $precedes );
+ }
}
}
$issue->save($cil);
# if we want to add or commit this issue
- if ( $args->{add} or $args->{commit} ) {
- $cil->vcs->add( $cil, $issue );
+ if ( $cil->UseGit ) {
+ if ( $args->{add} or $args->{commit} ) {
+ $cil->git->add( $cil, $issue );
+ }
}
push @issues, $issue;
}
- # if we want to commit these issues
- if ( $args->{commit} ) {
- $cil->vcs->commit_multiple( $cil, "Status changed to '$status'", @issues );
+ if ( $cil->UseGit ) {
+ # if we want to commit these issues
+ if ( $args->{commit} ) {
+ $cil->git->commit_multiple( $cil, "Status changed to '$status'", @issues );
+ }
}
}
$issue->AssignedTo( CIL::Utils->user($cil) );
$issue->save($cil);
- # if we want to add or commit this issue
- if ( $args->{add} or $args->{commit} ) {
- $cil->vcs->add( $cil, $issue );
- }
-
- # if we want to commit this issue
- if ( $args->{commit} ) {
- $cil->vcs->commit( $cil, 'Issue Stolen', $issue );
+ if ( $cil->UseGit ) {
+ # if we want to add or commit this issue
+ if ( $args->{add} or $args->{commit} ) {
+ $cil->git->add( $cil, $issue );
+ }
+
+ # if we want to commit this issue
+ if ( $args->{commit} ) {
+ $cil->git->commit( $cil, 'Issue Stolen', $issue );
+ }
}
CIL::Utils->display_issue_full($cil, $issue);
sub run {
my ($self, $cil, undef, $issue_name) = @_;
- CIL::Utils->fatal("the 'VCS' option in your .cil file is not set")
- unless defined $cil->VCS;
-
- CIL::Utils->fatal("the 'VCS' option currently only supports values of 'Git'")
- unless $cil->VCS eq 'Git';
+ CIL::Utils->fatal("to use this feature the 'UseGit' option in your .cil file should be set")
+ unless $cil->UseGit;
my $issue = CIL::Utils->load_issue_fuzzy($cil, $issue_name);
sub run {
my ($self, $cil, $args, $issue_name) = @_;
+ CIL::Utils->fatal("to use this feature the 'UseGit' option in your .cil file should be set")
+ unless $cil->UseGit;
+
# firstly, read the issue in
my $issue = CIL::Utils->load_issue_fuzzy( $cil, $issue_name );
# right, got it's name, let's see if there is a branch for it
- use Data::Dumper;
- my @branches = $cil->vcs->branches();
+ my @branches = $cil->git->branches();
my $branch = {};
foreach ( @branches ) {
$branch->{substr $_, 2} = 1;
}
if ( exists $branch->{$issue->name} ) {
- $cil->vcs->switch_to_branch( $issue->name );
+ $cil->git->switch_to_branch( $issue->name );
}
else {
- $cil->vcs->create_branch( $issue->name );
+ $cil->git->create_branch( $issue->name );
}
# now that we've switched branches, load the issue in again (just in case)
#
## ----------------------------------------------------------------------------
-package CIL::VCS::Git;
+package CIL::Git;
use strict;
use warnings;
use Carp;
-
-use base qw(CIL::VCS::Factory);
-
-sub post_add {
- my ($self, $issue) = @_;
-
- my $issue_dir = $issue->cil->IssueDir();
- my @files;
- push @files, "$issue_dir/i_" . $issue->name . '.cil';
- push @files, map { "$issue_dir/c_${_}.cil" } @{ $issue->CommentList };
- push @files, map { "$issue_dir/a_${_}.cil" } @{ $issue->AttachmentList };
-
- return [ "git add @files" ];
-}
-
use Git;
+use base qw(Class::Accessor);
+
sub git {
my $self = shift;
$self->{git} ||= Git->repository;
+++ /dev/null
-## ----------------------------------------------------------------------------
-# cil is a Command line Issue List
-# Copyright (C) 2008 Andrew Chilton
-#
-# This file is part of 'cil'.
-#
-# cil is free software: you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation, either version 3 of the License, or (at your option) any later
-# version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-# details.
-#
-# You should have received a copy of the GNU General Public License along with
-# this program. If not, see <http://www.gnu.org/licenses/>.
-#
-## ----------------------------------------------------------------------------
-
-package CIL::VCS::Factory;
-
-use strict;
-use warnings;
-use Carp;
-
-use base qw( Class::Factory );
-
-__PACKAGE__->register_factory_type( Null => 'CIL::VCS::Null' );
-__PACKAGE__->register_factory_type( Git => 'CIL::VCS::Git' );
-
-foreach my $method_name ( qw(post_add glob_rev file_exists dir_exists get_fh) ) {
- my $method = sub {
- my ($self) = @_;
- my $class = ref $self || $self;
- die "Method '$method_name' not overriden in derived class '$class'";
- };
-
- no strict 'refs';
- *{$method_name} = $method;
-}
-
-## ----------------------------------------------------------------------------
-1;
-## ----------------------------------------------------------------------------
+++ /dev/null
-## ----------------------------------------------------------------------------
-# cil is a Command line Issue List
-# Copyright (C) 2008 Andrew Chilton
-#
-# This file is part of 'cil'.
-#
-# cil is free software: you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation, either version 3 of the License, or (at your option) any later
-# version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-# details.
-#
-# You should have received a copy of the GNU General Public License along with
-# this program. If not, see <http://www.gnu.org/licenses/>.
-#
-## ----------------------------------------------------------------------------
-
-package CIL::VCS::Null;
-
-use strict;
-use warnings;
-use Carp;
-
-use base qw(CIL::VCS::Factory);
-
-foreach my $method_name ( qw(post_add) ) {
- no strict 'refs';
- *{"CIL::VCS::Null::$method_name"} = sub {};
-}
-
-foreach my $method_name ( qw(UserName UserEmail) ) {
- no strict 'refs';
- *{"CIL::VCS::Null::$method_name"} = sub { return ''; };
-}
-
-## ----------------------------------------------------------------------------
-1;
-## ----------------------------------------------------------------------------