commit 62d64d68f6b959ae87d3d313345ada53f2023234
Author: spesk1 <spesk@pm.me>
Date: Wed Jun 5 20:35:16 2019 -0400
Added config file fuctionality that can be expanded and warning if youre not using the local user you have configured in the config file
diff --git a/README.md b/README.md
index 1a1ae47..3d19763 100644
--- a/README.md
+++ b/README.md
@@ -33,10 +33,8 @@ Usage:
* Can be used with interactive mode
```
-# TODO:
+## TODO - Features:
+* Warn about upstream updates
-## Features:
-* No more ideas. Open to suggestions.
-
-## Stuff to fix:
+## TODO - Stuff to fix:
* multipule TODO:'s in various files
diff --git a/example.config b/example.config
new file mode 100644
index 0000000..da9d15f
--- /dev/null
+++ b/example.config
@@ -0,0 +1,4 @@
+# Warn user if following user is not set in .git/config or global user is not as below
+UserWarn = "true"
+user.name = "spesk1"
+user.email = "spesk@pm.me"
diff --git a/install.sh b/install.sh
index 42e2673..33eecf1 100755
--- a/install.sh
+++ b/install.sh
@@ -10,7 +10,7 @@ fi
if [ ! -d $libDir ]; then
echo "Making $libDir"
- mkdir -p $libDir
+ sudo mkdir -p $libDir
fi
echo "Copying bin"
diff --git a/lib/SimplyGit/Git.pm b/lib/SimplyGit/Git.pm
index 6ea4e58..7212b49 100644
--- a/lib/SimplyGit/Git.pm
+++ b/lib/SimplyGit/Git.pm
@@ -5,7 +5,7 @@ use Log::Log4perl qw(:easy);
use lib ".";
use SimplyGit::Shellex qw(shellex findBin);
use Exporter qw(import);
-our @EXPORT_OK = qw(readConfig getStatus returnState addFiles commitChanges pushChanges stashAndReset resetFromUpstream updateGitIgnore appendRepoUserConfig);
+our @EXPORT_OK = qw(readConfig getStatus returnState addFiles commitChanges pushChanges stashAndReset resetFromUpstream updateGitIgnore appendRepoUserConfig parseSGConfig warnOnUser);
# TODO: Add info/debug logging for all subroutines
@@ -20,6 +20,49 @@ sub checkPath($$) {
}
+sub warnOnUser($$$) {
+
+ my $user = shift;
+ my $email = shift;
+ my $logger = shift;
+
+ my $gitCmd = findBin("git",$logger);
+ my $configuredUser = shellex("$gitCmd config --get user.name",$logger);
+ my $configuredEmail = shellex("$gitCmd config --get user.email",$logger);
+
+ if ( $configuredUser ne $user || $configuredEmail ne $email ) {
+ print "***************\n";
+ print "Your configured user/email don't match what you declared in the config file!\n";
+ print "Desired User: $user\nConfigured User: $configuredUser\nDesired Email: $email\nConfigured Email: $configuredEmail\n";
+ print "***************\n";
+ }
+
+}
+
+sub parseSGConfig($$) {
+
+ my $config = shift;
+ my $logger = shift;
+ if ( ! -e $config ) {
+ $logger->error("$config doesn't look like a regular file, exiting...");
+ exit 1;
+ }
+ my $catCmd = findBin("cat",$logger);
+ my @configLines = split("\n",shellex("$catCmd $config",$logger));
+ my %configHash;
+ foreach my $line ( @configLines ) {
+ chomp $line;
+ if ( $line =~ m/^(.*)\ =\ "(.*)"$/ ) {
+ $configHash{$1} = $2;
+ }
+ }
+
+ if ( defined $configHash{'UserWarn'} ) {
+ warnOnUser($configHash{'user.name'},$configHash{'user.email'},$logger);
+ }
+
+}
+
sub returnConfigPath($$) {
my $path = shift;
diff --git a/lib/SimplyGit/Shellex.pm b/lib/SimplyGit/Shellex.pm
index b7ef456..0f35969 100644
--- a/lib/SimplyGit/Shellex.pm
+++ b/lib/SimplyGit/Shellex.pm
@@ -14,6 +14,7 @@ sub shellex {
}
my $output = `$cmd 2>&1`;
+ chomp $output;
my $rc = $?;
if ( defined $logger && $logger ne '' ) {
$logger->info("Returned: $rc");
diff --git a/sg b/sg
index e9d0010..36bee9f 100755
--- a/sg
+++ b/sg
@@ -8,7 +8,7 @@ use Log::Log4perl qw(:easy);
# TODO: This needs to be scoped properly
use lib "/usr/local/lib";
use SimplyGit::Shellex qw(shellex findBin);
-use SimplyGit::Git qw(readConfig getStatus returnState addFiles commitChanges pushChanges stashAndReset resetFromUpstream updateGitIgnore appendRepoUserConfig);
+use SimplyGit::Git qw(readConfig getStatus returnState addFiles commitChanges pushChanges stashAndReset resetFromUpstream updateGitIgnore appendRepoUserConfig parseSGConfig warnOnUser);
# TODO: This should maybe be more robust?
if ( ! -d ".git" ) {
@@ -23,6 +23,7 @@ sub initSG($) {
chomp $homeDir;
my $path = $homeDir . "/" . $sgDir;
my $logFile = $homeDir . "/" . $sgDir . "/" . "sgLog.txt";
+ my $configFile = $homeDir . "/" . $sgDir . "/" . "sg.config";
if ( ! -d $path ) {
print "Creating $path\n";
shellex("mkdir $path");
@@ -33,19 +34,29 @@ sub initSG($) {
shellex("touch $logFile");
}
- return ( $path, $logFile );
+ if ( ! -f $configFile ) {
+ print "Creating $logFile\n";
+ shellex("touch $logFile");
+ }
+
+ return ( $path, $logFile, $configFile );
}
-my ( $sgPath, $sgLogFile ) = initSG(".sg");
+my ( $sgPath, $sgLogFile, $sgConfigFile ) = initSG(".sg");
sub getLogName { return $sgLogFile; };
my $log_conf = q(
- log4perl.rootLogger = ERROR, LOG1
+ log4perl.rootLogger = ERROR, LOG1, screen
log4perl.appender.LOG1 = Log::Log4perl::Appender::File
log4perl.appender.LOG1.filename = sub { getLogName(); }
log4perl.appender.LOG1.mode = append
log4perl.appender.LOG1.layout = Log::Log4perl::Layout::PatternLayout
- log4perl.appender.LOG1.layout.ConversionPattern = %d %p %m %n
+ log4perl.appender.LOG1.layout.ConversionPattern = %d %p >> %m %n
+
+ log4perl.appender.screen = Log::Log4perl::Appender::Screen
+ log4perl.appender.screen.stderr = 0
+ log4perl.appender.screen.layout = PatternLayout
+ log4perl.appender.screen.layout.ConversionPattern = %d %p >> %m %n
);
Log::Log4perl::init(\$log_conf);
@@ -68,6 +79,7 @@ GetOptions(
'configure-local-user',
'user=s',
'email=s',
+ 'config-file=s',
);
sub printHelp {
@@ -101,6 +113,9 @@ Usage:
Configure local git user
* Can be used with interactive mode
+ --config-file
+ Default is ~/.sg/sg.config, can use this opt to use another file
+
EOF
;
@@ -182,11 +197,14 @@ sub parseArgs {
}
}
+ if ( ! defined $args{'config-file'} ) {
+ $args{'config-file'} = $sgConfigFile;
+ }
+
}
parseArgs();
-#print "Args parsed successfully\n";
-#exit 0;
+parseSGConfig($args{'config-file'},$logger);
# TODO: This sub could be more concise with a sub to print array refs
if ( defined $args{'view'} ) {