Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Check for remote origin before sycing. #6

Merged
merged 1 commit into from

2 participants

@throughnothing

This will prevent errors when running simple commands if you only have a
local git repo setup ond don't have a remote origin to sync to.

bin/notes
@@ -68,6 +68,11 @@ sub notes_dir { dir( $ENV{APP_NOTES_DIR} ) || dir( $ENV{HOME}, '.notes' ) }
sub notes_repo { file( notes_dir, '.git' ) }
sub auto_sync { $ENV{APP_NOTES_AUTOSYNC} // 1 }
+sub has_origin {
+ my ( $c ) = @_;
+ return grep { /^origin$/ } split ' ', $c->stash->{git}->run( 'remote' );

Why are we checking for a remote named origin? Why not check for any remote?

@throughnothing Owner

Because git push and git pull require origin. And I don't want to get into allowing multiple non-origin remotes and allowing them to set what remote they want etc. origin is standard for git, and required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@throughnothing Check for remote origin before sycing.
This will prevent errors when running simple commands
if you only have a local git repo setup ond don't have
a remote origin to sync to.
ef07c93
@throughnothing throughnothing merged commit 55f045e into master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 10, 2012
  1. Check for remote origin before sycing.

    authored
    This will prevent errors when running simple commands
    if you only have a local git repo setup ond don't have
    a remote origin to sync to.
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 0 deletions.
  1. +7 −0 bin/notes
View
7 bin/notes
@@ -57,6 +57,7 @@ sub invalid {
my $cmd = $c->cmd;
($cmd) = grep { /^$cmd/ } $c->commands;
$cmd ? $c->execute( $cmd ) : $c->execute( 'help' );
+ return; # This makes the command name not be printed from the last line
}
App::Rad->run;
@@ -68,6 +69,10 @@ sub notes_dir { dir( $ENV{APP_NOTES_DIR} ) || dir( $ENV{HOME}, '.notes' ) }
sub notes_repo { file( notes_dir, '.git' ) }
sub auto_sync { $ENV{APP_NOTES_AUTOSYNC} // 1 }
+sub has_origin {
+ grep { /^origin$/ } split ' ', $_[0]->stash->{git}->run( 'remote' )
+}
+
sub find_notes {
my ( $c, %args ) = @_;
my $sort = $args{sort} // 1;
@@ -230,6 +235,8 @@ sub show {
sub sync {
my ( $c, %args ) = @_;
+ return unless has_origin( $c );
+
my $output = capture {
$c->stash->{git}->run( 'pull' ) unless $args{push_only};
$c->stash->{git}->run( 'push' ) unless $args{pull_only};
Something went wrong with that request. Please try again.