Skip to content

Commit a1e1900

Browse files
committed
Merge branch 'ss/describe-dirty-in-the-right-directory'
"git --work-tree=$there --git-dir=$here describe --dirty" did not work correctly as it did not pay attention to the location of the worktree specified by the user by mistake, which has been corrected. * ss/describe-dirty-in-the-right-directory: t6120: test for describe with a bare repository describe: setup working tree for --dirty
2 parents d219b7f + c801170 commit a1e1900

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎builtin/describe.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
630630
struct argv_array args = ARGV_ARRAY_INIT;
631631
int fd, result;
632632

633+
setup_work_tree();
633634
read_cache();
634635
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
635636
NULL, NULL, NULL);

‎t/t6120-describe.sh‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,46 @@ test_expect_success 'rename tag Q back to A' '
143143
test_expect_success 'pack tag refs' 'git pack-refs'
144144
check_describe A-* HEAD
145145

146+
test_expect_success 'describe works from outside repo using --git-dir' '
147+
git clone --bare "$TRASH_DIRECTORY" "$TRASH_DIRECTORY/bare" &&
148+
git --git-dir "$TRASH_DIRECTORY/bare" describe >out &&
149+
grep "^A-[1-9][0-9]\?-g[0-9a-f]\+$" out
150+
'
151+
146152
check_describe "A-*[0-9a-f]" --dirty
147153

154+
test_expect_success 'describe --dirty with --work-tree' '
155+
(
156+
cd "$TEST_DIRECTORY" &&
157+
git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
158+
) &&
159+
grep "^A-[1-9][0-9]\?-g[0-9a-f]\+$" out
160+
'
161+
148162
test_expect_success 'set-up dirty work tree' '
149163
echo >>file
150164
'
151165

152166
check_describe "A-*[0-9a-f]-dirty" --dirty
153167

168+
test_expect_success 'describe --dirty with --work-tree (dirty)' '
169+
(
170+
cd "$TEST_DIRECTORY" &&
171+
git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
172+
) &&
173+
grep "^A-[1-9][0-9]\?-g[0-9a-f]\+-dirty$" out
174+
'
175+
154176
check_describe "A-*[0-9a-f].mod" --dirty=.mod
155177

178+
test_expect_success 'describe --dirty=.mod with --work-tree (dirty)' '
179+
(
180+
cd "$TEST_DIRECTORY" &&
181+
git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty=.mod >"$TRASH_DIRECTORY/out"
182+
) &&
183+
grep "^A-[1-9][0-9]\?-g[0-9a-f]\+.mod$" out
184+
'
185+
156186
test_expect_success 'describe --dirty HEAD' '
157187
test_must_fail git describe --dirty HEAD
158188
'
@@ -303,8 +333,17 @@ test_expect_success 'describe chokes on severely broken submodules' '
303333
mv .git/modules/sub1/ .git/modules/sub_moved &&
304334
test_must_fail git describe --dirty
305335
'
336+
306337
test_expect_success 'describe ignoring a broken submodule' '
307338
git describe --broken >out &&
339+
grep broken out
340+
'
341+
342+
test_expect_success 'describe with --work-tree ignoring a broken submodule' '
343+
(
344+
cd "$TEST_DIRECTORY" &&
345+
git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --broken >"$TRASH_DIRECTORY/out"
346+
) &&
308347
test_when_finished "mv .git/modules/sub_moved .git/modules/sub1" &&
309348
grep broken out
310349
'

0 commit comments

Comments
 (0)