commit 6220d9670dcc67d02056a276f68b4fc2e41399ae
Author: Simon Waton <spw01@protonmail.com>
Date: Mon May 20 16:54:59 2019 -0400
Trying to figure out readConfig
diff --git a/README.md b/README.md
index 82bd1b3..a9dc8f8 100644
--- a/README.md
+++ b/README.md
@@ -2,8 +2,13 @@
Project to abstract some of the weirder git operations. Should always be able to be used alongside git, as opposed to trying to replace it outright.
+Mainly writing to learn more about Git and Perl, unlikely to be widely useful.
+
TODO:
+--read-config
+* dump git config (mainly a sub to be used internally)
+
--reset-from-master
* add soft and hard functionality, right now only 'soft' is implemented
diff --git a/lib/SimplyGit/Git.pm b/lib/SimplyGit/Git.pm
index 6e5cf12..e3ee858 100644
--- a/lib/SimplyGit/Git.pm
+++ b/lib/SimplyGit/Git.pm
@@ -5,17 +5,17 @@ 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);
+our @EXPORT_OK = qw(readConfig getStatus returnState addFiles commitChanges pushChanges stashAndReset resetFromUpstream);
sub readConfig {
- # TODO: This sub is probably not really needed for what I'm trying to do
- # git itself already parses this config...
+ # This sub is probably not really needed for what I'm trying to do
+ # git itself already parses this config...but an interesting exercise non the less
+ # and may be useful later
my $path = shift;
my $logger = shift;
- # TODO: Should pass in logger object as opposed to printing
if ( ! -d $path ) {
- print "readConfig did not recieve expected dir, exiting...\n";
+ $logger->error("$path doesn't look like a dir, exiting...");
exit 1;
}
my $gitConfigPath = $path . "/" . ".git/config";
@@ -23,17 +23,33 @@ sub readConfig {
my @configLines = split("\n",shellex("$catCmd $gitConfigPath",$logger));
my %gitConfig;
my @valueLines;
- my $headerCounter = 0;
+ my $lineCounter = 0;
foreach my $line ( @configLines ) {
- if ( $line =~ m/\[(.*)\]/ ) {
+ $lineCounter++;
+ #if ( $line =~ m/\[(.*)\]/ ) {
+ if ( $line =~ m/(\[.*\])/ ) {
#$valueLine =~ /\t(.*)\ =\ (.*)$/;
- $gitConfig{$1} = "";
- } else {
- push(@valueLines, $line);
+ $gitConfig{$1} = $lineCounter;
}
}
+ my @lineRange = values %gitConfig;
+ my @sortedRange = sort { $a <=> $b } @lineRange;
+ my $prevVal ;
+ foreach my $val ( @sortedRange ) {
+ print "Val is $val\n";
+ if ( ! defined $prevVal ) {
+ $prevVal = $val;
+ next;
+ } else {
+ print "Current var is $val and prevVar $prevVal\n";
+ my $lineDiff = ( $val - 1 ) . "-" . ( $prevVal + 1 );
+ print "lineDiff of vals is: $lineDiff \n";
+ $prevVal = $val;
+ }
+ }
+
return %gitConfig;
}
@@ -134,5 +150,13 @@ sub stashAndReset {
shellex("$gitCmd rebase",$logger);
}
+sub resetFromUpstream {
+ # git stash and git reset --hard and git pull ? I think
+}
+
+sub appendRepoUserConfig {
+
+
+}
diff --git a/sg b/sg
index 68e866e..7c6928a 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);
+use SimplyGit::Git qw(readConfig getStatus returnState addFiles commitChanges pushChanges stashAndReset resetFromUpstream);
if ( ! -d ".git" ) {
print "Not a git dir, exiting...\n";
@@ -59,8 +59,10 @@ GetOptions(
'interactive',
'view',
'reset-from-master',
+ 'reset-from-upstream',
'branch-from-master',
'commit-msg=s',
+ 'read-config',
);
sub printHelp {
@@ -146,6 +148,10 @@ if ( defined $args{'view'} ) {
}
}
+###
+# TODO: This args processing is dangerous and incomplete, need to write an args processor function
+###
+
# This functionality is mainly here to test building out Git.pm, and doesn't really offer anything that regular git doesn't
if ( defined $args{'push-all'} ) {
@@ -229,3 +235,19 @@ if ( defined $args{'reset-from-master'} ) {
stashAndReset($logger);
}
+
+if ( defined $args{'reset-from-upstream'} ) {
+
+ print "This does nothing right now\n";
+ resetFromUpstream($logger);
+
+}
+
+if ( defined $args{'read-config'} ) {
+
+ my %configHash = readConfig(".",$logger);
+ foreach my $key ( keys %configHash ) {
+ print "key is $key, vals is: $configHash{$key}\n";
+ }
+
+}