Fix reading of the ~/.cilrc (esp. in the absence of any Git information
authorAndrew Chilton <andychilton@gmail.com>
Sat, 23 Jan 2010 12:27:29 +0000 (01:27 +1300)
committerAndrew Chilton <andy@amalthea.(none)>
Sat, 23 Jan 2010 12:27:29 +0000 (01:27 +1300)
lib/CIL.pm

index e5065e296e9dedefbcb6d87df4cd5c69b47ad7a5..b73de9119792ea1406f83c52c89fa20d86fe2859 100644 (file)
@@ -234,12 +234,20 @@ sub read_config_user {
 
     my $filename = File::HomeDir->my_home() . '/.cilrc';
 
+    # firstly, set the default config
     my $cfg;
+    %$cfg = %$defaults_user;
+
+    # then read the ~/.cilrc file
     if ( -f $filename ) {
         $cfg = CIL::Utils->parse_cil_file( $filename );
     }
 
-    # set each config to be either the user defined one or the default
+    # for some settings, see if we can get it from Git
+    $cfg->{UserName} = eval { Git->repository->config( 'user.name' ) }  || $cfg->{UserName};
+    $cfg->{UserEmail} = eval { Git->repository->config( 'user.email' ) } || $cfg->{UserEmail};
+
+    # save them all internally
     foreach ( qw(UserName UserEmail AutoAssignSelf) ) {
         $self->$_( $cfg->{$_} || $defaults_user->{$_} );
     }