|
@@ -7,14 +7,13 @@ use Getopt::Long qw(GetOptions);
|
|
|
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 parseSGConfig warnOnUser);
|
|
|
-
|
|
|
-# TODO: This should maybe be more robust?
|
|
|
-if ( ! -d ".git" ) {
|
|
|
- print "Not a git dir, exiting...\n";
|
|
|
- exit 1;
|
|
|
-}
|
|
|
+use SimplyGit::Shellex qw(shellex findBin knocker);
|
|
|
+use SimplyGit::Git qw(
|
|
|
+ readConfig getStatus returnState addFiles
|
|
|
+ commitChanges pushChanges stashAndReset resetFromUpstream
|
|
|
+ updateGitIgnore appendRepoUserConfig parseSGConfig
|
|
|
+ warnOnUser basicClone
|
|
|
+);
|
|
|
|
|
|
sub initSG($) {
|
|
|
|
|
@@ -35,8 +34,8 @@ sub initSG($) {
|
|
|
}
|
|
|
|
|
|
if ( ! -f $configFile ) {
|
|
|
- print "Creating $logFile\n";
|
|
|
- shellex("touch $logFile");
|
|
|
+ print "Creating $configFile\n";
|
|
|
+ shellex("touch $configFile");
|
|
|
}
|
|
|
|
|
|
return ( $path, $logFile, $configFile );
|
|
@@ -80,8 +79,17 @@ GetOptions(
|
|
|
'user=s',
|
|
|
'email=s',
|
|
|
'config-file=s',
|
|
|
+ 'knock',
|
|
|
+ 'knock-clone=s',
|
|
|
+ 'help',
|
|
|
);
|
|
|
|
|
|
+# TODO: This should maybe be more robust?
|
|
|
+if ( ! -d ".git" && ! defined $args{'knock-clone'} && ! defined $args{'help'} ) {
|
|
|
+ print "Not a git dir, exiting...\n";
|
|
|
+ exit 1;
|
|
|
+}
|
|
|
+
|
|
|
sub printHelp {
|
|
|
|
|
|
my $help = <<EOF
|
|
@@ -115,6 +123,15 @@ Usage:
|
|
|
|
|
|
--config-file
|
|
|
Default is ~/.sg/sg.config, can use this opt to use another file
|
|
|
+ * See example.config
|
|
|
+
|
|
|
+ --knock
|
|
|
+ Will try and knock the defined git server at the defined ports before any operation
|
|
|
+ * See example.config
|
|
|
+
|
|
|
+ --knock-clone
|
|
|
+ Will try and knock the defined git server and clone the provided repo
|
|
|
+ * Will not check if you're in a git dir
|
|
|
|
|
|
EOF
|
|
|
;
|
|
@@ -134,6 +151,11 @@ if ( scalar keys %args < 1 ) {
|
|
|
|
|
|
sub parseArgs {
|
|
|
|
|
|
+ if ( defined $args{'help'} ) {
|
|
|
+ printHelp();
|
|
|
+ exit 0;
|
|
|
+ }
|
|
|
+
|
|
|
if ( defined $args{'view'} && scalar keys %args > 1 ) {
|
|
|
print "Can't pass other args with --view\n";
|
|
|
exit 1;
|
|
@@ -151,7 +173,7 @@ sub parseArgs {
|
|
|
|
|
|
if ( defined $args{'push-all'} ) {
|
|
|
foreach my $arg ( keys %args ) {
|
|
|
- if ( $arg eq "interactive" || $arg eq "commit-msg" || $arg eq "push-all" ) {
|
|
|
+ if ( $arg eq "interactive" || $arg eq "commit-msg" || $arg eq "push-all" || $arg eq "knock" ) {
|
|
|
next;
|
|
|
} else {
|
|
|
print "Can only pass --interactive and --commit-msg with --push-all\n";
|
|
@@ -201,6 +223,12 @@ sub parseArgs {
|
|
|
$args{'config-file'} = $sgConfigFile;
|
|
|
}
|
|
|
|
|
|
+ if ( defined $args{'knock-clone'} ) {
|
|
|
+ if ( scalar keys %args > 2 ) {
|
|
|
+ print "Knock clone accepts no other args\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
parseArgs();
|
|
@@ -208,9 +236,11 @@ my %sgConfig = parseSGConfig($args{'config-file'},$logger);
|
|
|
if ( defined $sgConfig{'UserWarn'} ) {
|
|
|
warnOnUser($sgConfig{'user.name'},$sgConfig{'user.email'},$logger);
|
|
|
}
|
|
|
-if ( defined $sgConfig{'Knock'} ) {
|
|
|
- foreach my $port ( @{$sgConfig{'ports'}} ) {
|
|
|
- print "Would knock $port\n";
|
|
|
+
|
|
|
+sub knock() {
|
|
|
+ if ( defined $sgConfig{'Knock'} && ( defined $args{'knock'} || defined $args{'knock-clone'} ) ) {
|
|
|
+ print "Knocking...\n";
|
|
|
+ knocker($sgConfig{'knock.target'},$sgConfig{'ports'},$logger);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -332,12 +362,16 @@ if ( defined $args{'push-all'} ) {
|
|
|
print "Canceling...\n";
|
|
|
exit 1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ knock();
|
|
|
my $gitOutput = pushChanges($logger);
|
|
|
print "Git returned:\n$gitOutput\n";
|
|
|
|
|
|
- } else {
|
|
|
+ }
|
|
|
+
|
|
|
+ else {
|
|
|
|
|
|
+ knock();
|
|
|
pushChanges($logger);
|
|
|
my $gitOutput = pushChanges($logger);
|
|
|
print "Git returned:\n$gitOutput\n";
|
|
@@ -349,6 +383,7 @@ if ( defined $args{'push-all'} ) {
|
|
|
|
|
|
if ( defined $args{'reset-from-master'} ) {
|
|
|
|
|
|
+ knock();
|
|
|
stashAndReset($logger);
|
|
|
|
|
|
}
|
|
@@ -360,8 +395,10 @@ if ( defined $args{'reset-from-upstream'} ) {
|
|
|
chomp $args{'upstream-url'};
|
|
|
shellex("$gitCmd remote add upstream $args{'upstream-url'}",$logger);
|
|
|
shellex("$gitCmd fetch upstream",$logger);
|
|
|
+ knock();
|
|
|
resetFromUpstream($logger);
|
|
|
} else {
|
|
|
+ knock();
|
|
|
resetFromUpstream($logger);
|
|
|
}
|
|
|
}
|
|
@@ -399,4 +436,7 @@ if ( defined $args{'configure-local-user'} ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+if ( defined $args{'knock-clone'} ) {
|
|
|
+ knock();
|
|
|
+ basicClone($args{'knock-clone'},$logger);
|
|
|
+}
|