From cfbdef424610ed377d10b3d33e1ae01bbe3d631b Mon Sep 17 00:00:00 2001 From: Oleg Pykhalov Date: Thu, 1 Feb 2018 10:25:00 +0300 Subject: [PATCH 1/2] VC.pm: also work in a git "worktree" * VC.pm (new): Also accept a ".git" file, which is what you get in a git worktree. --- VC.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VC.pm b/VC.pm index 4252c61..2c7acbc 100644 --- a/VC.pm +++ b/VC.pm @@ -132,7 +132,7 @@ sub new($%) } } - if (-d "$d/.git/objects") { + if (-d "$d/.git/objects" || -f "$d/.git") { $self->{name} = GIT; } elsif (-d "$d/.bzr/repository") { $self->{name} = BZR; -- 2.15.1.433.g936d1b989 From 037883d4d1f17561da7747684edccfd6154b1d73 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 4 Feb 2018 01:58:49 -0800 Subject: [PATCH 2/2] vc-dwim: also work with a git worktree * vc-dwim.pl (admin_dir): Also handle the case in which .git is a file, as it is for a git worktree. * tests/git-worktree: New file. * tests/Makefile.am (TESTS): Add it. * NEWS: Mention the fix. --- NEWS | 1 + tests/Makefile.am | 1 + tests/git-worktree | 20 ++++++++++++++++++++ vc-dwim.pl | 15 ++++++++++++++- 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100755 tests/git-worktree diff --git a/NEWS b/NEWS index de4c77c..91309b5 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ vc-dwim NEWS -*- outline -*- * Noteworthy changes in release ?.? (????-??-??) [?] + vc-dwim and vc-chlog now also work with git worktree directories * Noteworthy changes in release 1.8 (2017-01-14) [stable] diff --git a/tests/Makefile.am b/tests/Makefile.am index 457cc0f..c0a6549 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -14,6 +14,7 @@ TESTS = \ subdir-middle \ add-empty \ git-mv \ + git-worktree \ two-line-attr \ cl-other-user \ cl-syntax \ diff --git a/tests/git-worktree b/tests/git-worktree new file mode 100755 index 0000000..0104d4b --- /dev/null +++ b/tests/git-worktree @@ -0,0 +1,20 @@ +#!/bin/sh +# Ensure things work in a git worktree, for which .git is a file. + +. "${srcdir=.}/init.sh"; path_prepend_ .. +print_ver_ vc-dwim + +require_git_ + +git init > /dev/null \ + && touch x \ + && git add . \ + && git commit -m m . > /dev/null \ + && git worktree add wt \ + && cd wt \ + || framework_failure_ + +fail=0 +vc-dwim --init || fail=1 + +Exit $fail diff --git a/vc-dwim.pl b/vc-dwim.pl index c869319..5dbbdab 100755 --- a/vc-dwim.pl +++ b/vc-dwim.pl @@ -690,11 +690,24 @@ sub check_attribution($$) or die "$ME: --author/ChangeLog mismatch:\n $$author\n $name_and_email\n"; } -# Return the name of the/an admin directory residing in +# Return the name of the/an admin directory associated with # the current directory. If there is none, return undef. sub admin_dir() { + # This is the usual case: a .git directory. -d '.git/objects' and return '.git'; + # With a git worktree, .git is a file containing a line of this form: + # gitdir: /abs/dir + my $git_file = '.git'; + if (-f $git_file) + { + # Read .git, and extract the name after "gitdir: " + my $fh = new IO::File $git_file, 'r' + or die "$ME: can't open `$git_file' for reading: $!\n"; + my $line = <$fh>; + defined $line && $line =~ /^gitdir: (.+)$/ + and return $1; + } -d '.hg' and return '.hg'; -d 'CVS' and return 'CVS'; -d '.svn' and return '.svn'; -- 2.15.1.433.g936d1b989