#!/usr/bin/perl

use strict;
use warnings;
use Gear::Remotes;
use Gear::Remotes::SpecComment;

my $topdir=Gear::Git::Helper::get_git_toplevel();
die "fatal: $topdir - not a gear repository.\n" unless &Gear::Remotes::check_if_gear_dir($topdir);
my $gear_remotes_file=&Gear::Remotes::get_gear_remotes_file($topdir);
if (-e $gear_remotes_file) {
    my $gear_remotes=Gear::Remotes->new(-autorestore=>1);
} else {
    my ($sourcegit,$comment)=Gear::Remotes::SpecComment::get_spec_comment();
    if ($sourcegit) {
	warn "gear-remotes-restore: $gear_remotes_file not found.
However, spec file has a comment
$comment $sourcegit

run
gear-remotes-set-from-spec-comment to set the url from spec file comment
or
gear-remotes-set-from-url <url> to set the git url manually.
";
	exit 1;
    } else {
	warn "gear-remotes-restore: $gear_remotes_file not found.
Find git repository url manually and run
gear-remotes-set-from-url <url>.
";
	exit 1;
    }
}

__END__

=head1	NAME

gear-remotes-restore - create .git/config entry from .gear/upstream/remotes file

=head1	SYNOPSIS

B<gear-remotes-restore>
[I<remotename>]

=head1	DESCRIPTION

B<gear-remotes-restore> restores .git/config [upstream] entry
from file I<.gear/upstream/remotes>.

=head1	OPTIONS

none.

=head1	AUTHOR

Written by Igor Vlasenko <viy@altlinux.org>.

=head1	COPYING

Copyright (c) 2014-2018 Igor Vlasenko, ALT Linux Team.

This is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.

=cut

