commit 2eb4277f87c8862e3f44fb8edbfb1b82b83fa221
Author: spesk1 <spesk@pm.me>
Date: Tue May 21 22:56:08 2019 -0400
Added functionality to add upstream
diff --git a/lib/SimplyGit/Shellex.pm b/lib/SimplyGit/Shellex.pm
index 85e134d..b7ef456 100644
--- a/lib/SimplyGit/Shellex.pm
+++ b/lib/SimplyGit/Shellex.pm
@@ -24,7 +24,7 @@ sub shellex {
$logger->error("$cmd returned non-zero: $rc");
}
- print "$cmd returned non-zero: $rc, exiting\n";
+ print "$cmd returned non-zero: $rc\n";
exit 1;
}
diff --git a/sg b/sg
index 2b9e424..4e1be11 100755
--- a/sg
+++ b/sg
@@ -64,6 +64,7 @@ GetOptions(
'view',
'reset-from-master',
'reset-from-upstream',
+ 'upstream-url=s',
'commit-msg=s',
'dump-config',
'configure-local-user',
@@ -93,8 +94,10 @@ Usage:
--reset-from-master
Reset all current changes so that the file tree matches upstream/master
- --reset-from-upstream
+ --reset-from-upstream [ --upstream-url ]
If upstream is defined will reset local branch to match upstream ( does not push changes by default )
+ * Assumes you have an upstream configured
+ * Pass SSH/HTTPS URL to --upstream-url to add an upstream
--configure-local-user [--user,--email]
Configure local git user
@@ -165,9 +168,20 @@ sub parseArgs {
}
}
- if ( defined $args{'reset-from-upstream'} && scalar keys %args > 1 ) {
- print "Cannot call --reset-from-upstream with any other args\n";
- exit 1;
+ if ( defined $args{'reset-from-upstream'} ) {
+ if ( scalar keys %args > 2 ) {
+ print "Can only pass --upstream-url with --reset-from-upstream\n";
+ exit 1;
+ }
+
+ foreach my $arg ( keys %args ) {
+ if ( $arg eq "reset-from-upstream" || $arg eq "upstream-url" ) {
+ next;
+ } else {
+ print "Can only pass --upstream-url with --reset-from-upstream\n";
+ exit 1;
+ }
+ }
}
}
@@ -316,8 +330,15 @@ if ( defined $args{'reset-from-master'} ) {
if ( defined $args{'reset-from-upstream'} ) {
- resetFromUpstream($logger);
-
+ if ( defined $args{'upstream-url'} ) {
+ print "Setting upstream to $args{'upstream-url'}\n";
+ chomp $args{'upstream-url'};
+ shellex("$gitCmd remote add upstream $args{'upstream-url'}",$logger);
+ shellex("$gitCmd fetch upstream",$logger);
+ resetFromUpstream($logger);
+ } else {
+ resetFromUpstream($logger);
+ }
}
if ( defined $args{'dump-config'} ) {