commit 2c46a5ccdd62aa04233fd50ebc8f6600ea394a88
Author: spesk1 <spesk@pm.me>
Date: Tue Jun 11 10:48:29 2019 -0400
Added a few more knocking features
diff --git a/README.md b/README.md
index 1d51999..919b798 100644
--- a/README.md
+++ b/README.md
@@ -4,49 +4,53 @@ Project to abstract some of the weirder git operations or things that I forget.
Mainly writing to learn more about Git and Perl, unlikely to be widely useful.
```
-simply-git
-Usage:
- --view
- Display git status of files and other information
-
- --dump-config
- Dump .git/config to STDOUT. Not really useful but exposed for testing of reading config into internal data structure
-
- --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
-
- --reset-from-master
- Reset all current changes so that the file tree matches origin master
-
- --reset-from-upstream [ --upstream-url ]
- If upstream is defined will reset local branch to match upstream ( does not push changes to origin )
- * 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
- * Can be used with interactive mode
-
- --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
+simply-git
+Usage:
+ --view
+ Display git status of files and other information
+
+ --dump-config
+ Dump .git/config to STDOUT. Not really useful but exposed for testing of reading config into internal data structure
+
+ --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
+
+ --reset-from-master
+ Reset all current changes so that the file tree matches origin master
+
+ --reset-from-upstream [ --upstream-url ]
+ If upstream is defined will reset local branch to match upstream ( does not push changes to origin )
+ * 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
+ * Can be used with interactive mode
+
+ --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
+ * Can pass this by itself to perform a knock and exit
+
+ --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
+
+ --knock-pull
+ Will try and knock the defined git server and git pull
```
## Deps
-* perl, Log4Perl, which, git
+* perl, Log4Perl, which, git, nmap
## Installation
Can use provided install.sh to install
@@ -56,3 +60,4 @@ Can use provided install.sh to install
## TODO - Stuff to fix:
* multipule TODO:'s in various files
+* Code is getting messy, see TODOs
diff --git a/example.config b/example.config
index f5ac5c7..2548bc4 100644
--- a/example.config
+++ b/example.config
@@ -5,4 +5,5 @@ user.email = "spesk@pm.me"
# Use if your git server requires port knocking
Knock = "true"
+knock.target = "mygitserver.com"
ports = [ "1111", "2222" ]
diff --git a/lib/SimplyGit/Git.pm b/lib/SimplyGit/Git.pm
index c5369e5..ab8c64a 100644
--- a/lib/SimplyGit/Git.pm
+++ b/lib/SimplyGit/Git.pm
@@ -9,7 +9,7 @@ our @EXPORT_OK = qw(
readConfig getStatus returnState addFiles
commitChanges pushChanges stashAndReset resetFromUpstream
updateGitIgnore appendRepoUserConfig parseSGConfig
- warnOnUser basicClone
+ warnOnUser basicClone basicPull
);
# TODO: Add info/debug logging for all subroutines
@@ -337,3 +337,12 @@ sub basicClone($$) {
print "Successfully cloned $cloneTarget\n";
}
+
+sub basicPull($) {
+
+ my $logger = shift;
+ my $gitCmd = findBin("git",$logger);
+ my $gitPullReturn = shellex("$gitCmd pull",$logger);
+ print "git pull returned:\n$gitPullReturn\n";
+
+}
diff --git a/sg b/sg
index f1961e8..3b47d3f 100755
--- a/sg
+++ b/sg
@@ -12,7 +12,7 @@ use SimplyGit::Git qw(
readConfig getStatus returnState addFiles
commitChanges pushChanges stashAndReset resetFromUpstream
updateGitIgnore appendRepoUserConfig parseSGConfig
- warnOnUser basicClone
+ warnOnUser basicClone basicPull
);
sub initSG($) {
@@ -82,10 +82,11 @@ GetOptions(
'knock',
'knock-clone=s',
'help',
+ 'knock-pull',
);
# TODO: This should maybe be more robust?
-if ( ! -d ".git" && ! defined $args{'knock-clone'} && ! defined $args{'help'} ) {
+if ( ! -d ".git" && ( ! defined $args{'knock-clone'} && ! defined $args{'knock'} && ! defined $args{'help'} ) ) {
print "Not a git dir, exiting...\n";
exit 1;
}
@@ -128,11 +129,15 @@ Usage:
--knock
Will try and knock the defined git server at the defined ports before any operation
* See example.config
+ * Can pass this by itself to perform a knock and exit
--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
+ --knock-pull
+ Will try and knock the defined git server and git pull
+
EOF
;
@@ -225,7 +230,15 @@ sub parseArgs {
if ( defined $args{'knock-clone'} ) {
if ( scalar keys %args > 2 ) {
- print "Knock clone accepts no other args\n";
+ print "--knock-clone accepts no other args\n";
+ exit 1;
+ }
+ }
+
+ if ( defined $args{'knock-pull'} ) {
+ if ( scalar keys %args > 2 ) {
+ print "--knock-pull accepts no other args\n";
+ exit 1;
}
}
@@ -233,17 +246,22 @@ sub parseArgs {
parseArgs();
my %sgConfig = parseSGConfig($args{'config-file'},$logger);
-if ( defined $sgConfig{'UserWarn'} ) {
+if ( defined $sgConfig{'UserWarn'} && -d ".git" ) {
warnOnUser($sgConfig{'user.name'},$sgConfig{'user.email'},$logger);
}
sub knock() {
- if ( defined $sgConfig{'Knock'} && ( defined $args{'knock'} || defined $args{'knock-clone'} ) ) {
+ if ( defined $sgConfig{'Knock'} && ( defined $args{'knock'} || defined $args{'knock-clone'} || defined $args{'knock-pull'} ) ) {
print "Knocking...\n";
knocker($sgConfig{'knock.target'},$sgConfig{'ports'},$logger);
}
}
+if ( defined $args{'knock'} && scalar keys %args == 2 ) {
+ print "Just knocking then exiting...\n";
+ knock();
+ exit 1;
+}
# TODO: This sub could be more concise with a sub to print array refs
if ( defined $args{'view'} ) {
@@ -440,3 +458,8 @@ if ( defined $args{'knock-clone'} ) {
knock();
basicClone($args{'knock-clone'},$logger);
}
+
+if ( defined $args{'knock-pull'} ) {
+ knock();
+ basicPull($logger);
+}