Subject: bug#30316: closed (Re: [Bug-vc-dwim] bug#30316: [PATCH] maint: find git worktree)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 05 Feb 2018 03:28:02 +0000

Your bug report

#30316: [PATCH] maint: find git worktree

which was filed against the vc-dwim package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
30316: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=30316
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: [Bug-vc-dwim] bug#30316: [PATCH] maint: find git worktree
From: Jim Meyering <[email-masked]>
To: Oleg Pykhalov <[email-masked]>
Cc: [email-masked]
Date: Mon, 5 Feb 2018 16:26:39 +1300
List-Id: <debbugs-submit.debbugs.gnu.org>

On Thu, Feb 1, 2018 at 9:45 PM, Oleg Pykhalov <[email-masked]> wrote:
> In addion to my previous message.
>
> Oleg Pykhalov <[email-masked]> writes:
>
>> The following patch allows to use 'vc-chlog' in the Git worktree instead
>> of getting “can't determine version control system for DIRECTORY”.
>
> Probably a directory is needed, too.  I was little bit confused about
> that directory is a file and it worked for the first time because I have
> another version of vc-dwim installed simultaneously.  Apologies.
>
> Here is a new patch.

Thank you. I've pushed that along with two other commits that were
required to complete git worktree support.
Here are the changes I've just pushed:
From cfbdef424610ed377d10b3d33e1ae01bbe3d631b Mon Sep 17 00:00:00 2001
From: Oleg Pykhalov <[email-masked]>
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 <[email-masked]>
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

Subject: [PATCH] maint: find git worktree
From: Oleg Pykhalov <[email-masked]>
To: [email-masked]
Date: Thu, 01 Feb 2018 10:48:00 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello,

The following patch allows to use 'vc-chlog' in the Git worktree instead
of getting “can't determine version control system for DIRECTORY”.

From fb361218cdbceb8acaffa7f7049c41e1e892ca6e Mon Sep 17 00:00:00 2001
From: Oleg Pykhalov <[email-masked]>
Date: Thu, 1 Feb 2018 10:25:00 +0300
Subject: [PATCH] maint: find git worktree

* VC.pm (new): Find .git file instead of directory.
---
 VC.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/VC.pm b/VC.pm
index 4252c61..1eca5b8 100644
--- a/VC.pm
+++ b/VC.pm
@@ -132,7 +132,7 @@ sub new($%)
 	  }
 	}
 
-      if (-d "$d/.git/objects") {
+      if (-f "$d/.git") {
 	$self->{name} = GIT;
       } elsif (-d "$d/.bzr/repository") {
 	$self->{name} = BZR;
-- 
2.15.1

Thanks,
Oleg.