]> git.mjollnir.org Git - cil.git/commitdiff
importing user id from Git
authorYanick Champoux <yanick@babyl.dyndns.org>
Fri, 8 Aug 2008 18:09:25 +0000 (14:09 -0400)
committerAndrew Chilton <andychilton@gmail.com>
Thu, 4 Sep 2008 12:07:48 +0000 (00:07 +1200)
bin/cil
lib/CIL/VCS/Git.pm

diff --git a/bin/cil b/bin/cil
index 39db797000b1b7a5313cbd29001748c5da8e335f..00e706ad09f191313f32ce8a5256d57b9510effb 100755 (executable)
--- a/bin/cil
+++ b/bin/cil
@@ -143,6 +143,19 @@ sub cmd_init {
         fatal("Couldn't create '$issues_dir' directory: $!");
     }
 
+    my $username = "unknown";
+    my $user_email;
+
+    # are we in a Git repository?
+    my $VCSconfig = '';
+    if ( -d '.git' ) {
+        msg( 'git repository detected, setting VCS accordingly' );
+        $VCSconfig = 'VCS: git';
+        my $vcs = CIL::VCS::Factory->new( 'Git' );
+        $username = $vcs->username     if $vcs->username;
+        $user_email = $vcs->user_email if $vcs->user_email;
+    }
+
     # create a .cil file here also
     if ( $args->{bare} ) {
         unless ( touch $config ) {
@@ -152,7 +165,10 @@ sub cmd_init {
     }
     else {
         # write a default .cil file
-        write_file($config, <<'CONFIG');
+        write_file($config, <<"CONFIG");
+$VCSconfig
+UserName: $username
+UserEmail: $user_email
 StatusStrict: 1
 StatusAllowedList: New
 StatusAllowedList: InProgress
index 3a6f97c78d6fa68412343e40c8d7d18fe05fd474..a256b55a4a54a4e532287378bad44baada8a69c5 100644 (file)
@@ -85,6 +85,14 @@ sub get_fh {
     $self->git->command_output_pipe("cat-file", "blob", "$rev:$path");
 }
 
+sub username {
+    return $_[0]->git->config( 'user.name' );
+}
+
+sub user_email {
+    return $_[0]->git->config( 'user.email' );
+}
+
 ## ----------------------------------------------------------------------------
 1;
 ## ----------------------------------------------------------------------------