git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git-cvsimport does not like detached HEAD
@ 2007-04-03  8:23 Junio C Hamano
  2007-04-04 21:40 ` Martin Langhoff
  0 siblings, 1 reply; 2+ messages in thread
From: Junio C Hamano @ 2007-04-03  8:23 UTC (permalink / raw)
  To: Martin Langhoff; +Cc: git

In my day-job project, I use git-cvsimport with -i option to
treat the central CVS repository as if it is just a branch in a
remote git repository.  Since I hoard many changes in my git
repository and trickle only a few changes at a time to the
central CVS back, I keep shuffling and rebasing my commits on
top of what I obtain from CVS, and many times, my HEAD is
detached and not on a particular branch.

However, it seems git-cvsimport does not like to work when your
HEAD is detached.

Here is a minimum patch that seems to let me going, but I am not
quite sure what the implication is for letting orig_branch (and
last_branch) to default to "master" (I do not use "master"
branch for that project so maybe I am getting lucky).

---
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 1a1ba7b..a64219f 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -563,8 +563,11 @@ unless (-d $git_dir) {
 
 	open(F, "git-symbolic-ref HEAD |") or
 		die "Cannot run git-symbolic-ref: $!\n";
-	chomp ($last_branch = <F>);
-	$last_branch = basename($last_branch);
+	$last_branch = <F>;
+	if (defined $last_branch) {
+		chomp($last_branch);
+		$last_branch = basename($last_branch);
+	}
 	close(F);
 	unless ($last_branch) {
 		warn "Cannot read the last branch name: $! -- assuming 'master'\n";

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: git-cvsimport does not like detached HEAD
  2007-04-03  8:23 git-cvsimport does not like detached HEAD Junio C Hamano
@ 2007-04-04 21:40 ` Martin Langhoff
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Langhoff @ 2007-04-04 21:40 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Junio C Hamano wrote:
> In my day-job project, I use git-cvsimport with -i option to
> treat the central CVS repository as if it is just a branch in a
> remote git repository.  Since I hoard many changes in my git
> repository and trickle only a few changes at a time to the
> central CVS back, I keep shuffling and rebasing my commits on
> top of what I obtain from CVS, and many times, my HEAD is
> detached and not on a particular branch.

I don't quite understand detached HEAD very well so my reply may be
bogus... (I'm familiar with cg-seek, which seems to be a similar concept
of checking out an arbitrary commit in a mode where you are not allowed
to commit because you are not really at the tip of any branch).

> However, it seems git-cvsimport does not like to work when your
> HEAD is detached.

Yep - I can see how...

> Here is a minimum patch that seems to let me going, but I am not
> quite sure what the implication is for letting orig_branch (and
> last_branch) to default to "master" (I do not use "master"
> branch for that project so maybe I am getting lucky).

cvsimport should never write to 'master'*, so setting $last_branch to
master will mean that it will always switch to the branch it's importing
(and the switch will do the initialisation of temp index files, etc).
You could set it to '' and get the same effect, perhaps even safer.

* unless the cvs repo has a branch called 'master', and in that case
we're fsck'd.

Which leads me to think -- how magic is master anyway. Should we protect
it? The CVS repo could have a branchname collision with us on any
refname -- always make sure that repos where I do cvsimport are never
development repositories, which means that my dev branches are protected
from collisions. I think it's the only sane thing to do.

OTOH, it's trivial to say something like (warning, MUA-broken patch)

diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 1a1ba7b..73e0544 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -685,6 +685,9 @@ my (@old,@new,@skipped,%ignorebranch);
 # commits that cvsps cannot place anywhere...
 $ignorebranch{'#CVSPS_NO_BRANCH'} = 1;

+# protect 'master';
+$ignorebranch{'master'} = 1;
+
 sub commit {
        if ($branch eq $opt_o && !$index{branch} &&
!get_headref($branch, $git_dir)) {
            # looks like an initial commit


cheers,


m
-- 
-----------------------------------------------------------------------
Martin @ Catalyst .Net .NZ  Ltd, PO Box 11-053, Manners St,  Wellington
WEB: http://catalyst.net.nz/           PHYS: Level 2, 150-154 Willis St
OFFICE: +64(4)916-7224  UK: 0845 868 5733 ext 7224  MOB: +64(21)364-017
      Make things as simple as possible, but no simpler - Einstein
-----------------------------------------------------------------------

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-04-04 22:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-03  8:23 git-cvsimport does not like detached HEAD Junio C Hamano
2007-04-04 21:40 ` Martin Langhoff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).