Skip to content

Commit b64d2b0

Browse files
author
wu-lee
committed
Be more helpful when .git exists on first import
git-cvsimport will throw a cryptic error if .git exists and the expected CVS import ref defined bu the -o flag (by default "cvs/cvshead") does not exist. This is usually because the user mistakenly ran git init before first import. There's almost certainly a better solution but this will do for now.
1 parent 6acc298 commit b64d2b0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

bin/git-cvs

+29
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,21 @@ sub cvs_pull {
229229
230230
mkpath $gitworking;
231231
232+
# If .git exists, git-cvsimport will expect there to be a branch
233+
# with the name given by the -o flag, and will die if there isn't
234+
# one, with a cryptic error message. We try to make this more user
235+
# friendly by checking for this condition and giving a more helpful
236+
# error.
237+
if (-d "$gitworking/.git") {
238+
239+
my $tracking_ref = "$REMOTE_FOR_CVS/$CVS_HEAD_TRACKING_REF";
240+
my @tracking_ref_info = `git $gda show-ref $tracking_ref`;
241+
242+
@tracking_ref_info
243+
or croak "A .git directory exists but there is no tracking ref '$tracking_ref'";
244+
}
245+
246+
232247
# Find a unique filename for the log, so we don't clobber old logs
233248
# when we re-run.
234249
my $logfile = $self->logfile || $self->_unique_logfile;
@@ -717,6 +732,20 @@ if ($operation eq 'push') {
717732
}
718733

719734
eval { $gitcvs->cvs_pull(%params) };
735+
736+
# Perl's exceptions leave something to be desired. Expand certain
737+
# terse croaks from the $gitcvs object into fuller ones without
738+
# line-number info.
739+
if ($@ =~ /no tracking ref '(.*?)'/i) {
740+
die <<ERROR;
741+
Error: a .git directory exists already, but it hasn't a CVS import ref called
742+
'$1'. If this is your first import from CVS, you need to remove this
743+
pre-existing .git repository and try again. You should not run 'git
744+
init' before your first import. If it is not your first import,
745+
something is wrong, because $1 should already exist.
746+
ERROR
747+
}
748+
# other errors assumed internal, leave them as they are.
720749
die $@ if $@;
721750

722751
} else {

0 commit comments

Comments
 (0)