From 18ec1361d4eea49066aa12ccb2b173f196962f66 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 25 May 2019 11:34:04 +0200 Subject: git-branch-list: Make the branch list work in subdirectories When the current directory was not the Git root, the command wouldn't work. It expected to find the branch list database in the `.git` directory in the current directory. Make the program work even if the current directory is a subdirectory of the Git repository. --- git-branch-list | 3 ++- t/105-list-works-in-subdirectory.t | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 t/105-list-works-in-subdirectory.t diff --git a/git-branch-list b/git-branch-list index 13b3ed1..ed5ef34 100755 --- a/git-branch-list +++ b/git-branch-list @@ -18,7 +18,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -DATABASE=.git/info/git-branch-list +GIT_ROOT=$(git rev-parse --show-toplevel) +DATABASE="${GIT_ROOT}/.git/info/git-branch-list" VERSION=0.1.1 function initialise_database () { diff --git a/t/105-list-works-in-subdirectory.t b/t/105-list-works-in-subdirectory.t new file mode 100644 index 0000000..b236314 --- /dev/null +++ b/t/105-list-works-in-subdirectory.t @@ -0,0 +1,17 @@ +#!/usr/bin/env perl -w + +use strict; + +use Test::More; + +use Bin qw($BIN); + +mkdir 't-git-repo/subdirectory', 0755; + +chdir 't-git-repo/subdirectory' or die $!; + +my $branch_list = qx($BIN); +is $branch_list, '', 'must find database file'; + + +done_testing; -- cgit v1.2.3