@matheusbsbs / matheus-bagliano / commits / 8a5f2eac52
Fork 0

cvsimport: honor -i and non -i upon subsequent imports

Documentation says -i is "import only", so without it, subsequent import should update the current branch and working tree files in a sensible way. "A sensible way" defined by this commit is "act as if it is a git pull from foreign repository which happens to be CVS not git". So: - If importing into the current branch (note that cvsimport requires the tracking branch is pristine -- you checked out the tracking branch but it is your responsibility not to make your own commits there), fast forward the branch head and match the index and working tree using two-way merge, just like "git pull" does. - If importing into a separate tracking branch, update that branch head, and merge it into your current branch, again, just like "git pull" does. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Mar 17, 2006 at 14:08 UTC 8a5f2eac5271ba1efed353c0c0a992d6471a8d05
1 file changed +17 -1
git-cvsimport.perl
+17 -1
@@ -453,6 +453,7 @@ chdir($git_tree);
453 my $last_branch = "";
454 my $orig_branch = "";
455 my %branch_date;
456 +my $tip_at_start = undef;
457
458 my $git_dir = $ENV{"GIT_DIR"} || ".git";
459 $git_dir = getwd()."/".$git_dir unless $git_dir =~ m#^/#;
@@ -487,6 +488,7 @@ unless(-d $git_dir) {
488 $last_branch = "master";
489 }
490 $orig_branch = $last_branch;
491 + $tip_at_start = `git-rev-parse --verify HEAD`;
492
493 # populate index
494 system('git-read-tree', $last_branch);
@@ -873,7 +875,21 @@ if (defined $orig_git_index) {
875
876 # Now switch back to the branch we were in before all of this happened
877 if($orig_branch) {
876 - print "DONE; you may need to merge manually.\n" if $opt_v;
878 + print "DONE.\n" if $opt_v;
879 + if ($opt_i) {
880 + exit 0;
881 + }
882 + my $tip_at_end = `git-rev-parse --verify HEAD`;
883 + if ($tip_at_start ne $tip_at_end) {
884 + print "Fetched into the current branch.\n" if $opt_v;
885 + system(qw(git-read-tree -u -m),
886 + $tip_at_start, $tip_at_end);
887 + die "Fast-forward update failed: $?\n" if $?;
888 + }
889 + else {
890 + system(qw(git-merge cvsimport HEAD), "refs/heads/$opt_o");
891 + die "Could not merge $opt_o into the current branch.\n" if $?;
892 + }
893 } else {
894 $orig_branch = "master";
895 print "DONE; creating $orig_branch branch\n" if $opt_v;