82689837bdbae1f6b6b41a7a519326334c183587
commit 82689837bdbae1f6b6b41a7a519326334c183587
Author: Simon Waton <spw01@protonmail.com>
Date: Tue May 14 23:56:08 2019 -0400

Added stash/reset functionality and --commit-msg opt

diff --git a/lib/SimplyGit/Git.pm b/lib/SimplyGit/Git.pm
index 67b3657..6e5cf12 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);
+our @EXPORT_OK = qw(readConfig getStatus returnState addFiles commitChanges pushChanges stashAndReset);

sub readConfig {

@@ -99,6 +99,8 @@ sub addFiles {

}

+# TODO: Possibly worth returning output for commitChanges(), pushChanges(), stashAndReset, even if I'm not using it right now
+
sub commitChanges {

my $commitMsg = shift;
@@ -116,3 +118,21 @@ sub pushChanges {
my $output = shellex("$gitCmd push",$logger);

}
+
+sub stashAndReset {
+
+ my $logger = shift;
+ my $gitCmd = findBin("git",$logger);
+ shellex("$gitCmd stash",$logger);
+ my @stashList = split("\n", shellex("$gitCmd stash list",$logger));
+ my $stashCount = scalar @stashList;
+ foreach my $stashNum ( 1..$stashCount ) {
+ shellex("$gitCmd stash drop 0",$logger);
+ }
+
+ # TODO: Depending on use case need to do more here
+ shellex("$gitCmd rebase",$logger);
+}
+
+
+
diff --git a/sg b/sg
index 3a020df..68e866e 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);
+use SimplyGit::Git qw(readConfig getStatus returnState addFiles commitChanges pushChanges stashAndReset);

if ( ! -d ".git" ) {
print "Not a git dir, exiting...\n";
@@ -60,6 +60,7 @@ GetOptions(
'view',
'reset-from-master',
'branch-from-master',
+ 'commit-msg=s',
);

sub printHelp {
@@ -70,8 +71,10 @@ Usage:
--view
Display git status of files and other information

- --push-all
- Push all untracked and modified files (can be used with interactive mode)
+ --push-all [--commit-msg]
+ Push all untracked and modified files
+ * (can be used with interactive mode)
+ * can provide a commit msg with --commit-msg (otherwise a generic will be provided)

--interactive
Enable interactive mode with supported opts
@@ -183,11 +186,14 @@ if ( defined $args{'push-all'} ) {

addFiles(\@filesToCommit,$logger);

- if ( defined $args{'interactive'} ) {
+ if ( defined $args{'interactive'} && ! defined $args{'commit-msg'}) {
print "Enter a commit message: ";
my $input = <STDIN>;
chomp $input;
commitChanges($input,$logger);
+ } elsif ( defined $args{'commit-msg'} ) {
+ my $commitMsg = "$args{'commit-msg'}";
+ commitChanges($commitMsg,$logger);
} else {
my $epoch = time();
my $commitMsg = "Generic Commit at $epoch";
@@ -217,3 +223,9 @@ if ( defined $args{'push-all'} ) {


}
+
+if ( defined $args{'reset-from-master'} ) {
+
+ stashAndReset($logger);
+
+}