From d2dc177112073cd6da7ea746f216572b091a37c0 Mon Sep 17 00:00:00 2001 From: Peter Grayson Date: Mon, 21 Dec 2020 16:00:43 -0500 Subject: [PATCH] Repair `stg log` with patches from subdir If `stg log` was run from a worktree subdir (i.e. not from the root), and if patches were provided on the command line, nothing would be printed. This is due to the patch names being mapped to pathlimits to the underlying `git log` (or `gitk`) commands. This is resolved by using Repository.run(), which takes care to operate from the root, instead of plain Run, which runs from the current directory. Signed-off-by: Peter Grayson --- stgit/commands/log.py | 16 +++++++++++----- t/t0009-log.sh | 12 ++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/stgit/commands/log.py b/stgit/commands/log.py index 1aedcc4..5ecf9f3 100644 --- a/stgit/commands/log.py +++ b/stgit/commands/log.py @@ -1,7 +1,6 @@ from stgit.argparse import opt, patch_range from stgit.commands.common import DirectoryHasRepository, parse_patches from stgit.lib import log -from stgit.run import Run __copyright__ = """ Copyright (C) 2006, Catalin Marinas @@ -77,7 +76,7 @@ options = [ directory = DirectoryHasRepository() -def show_log(state, pathlim, num, full, show_diff): +def show_log(repository, state, pathlim, num, full, show_diff): cmd = ['git', 'log'] if num is not None and num > 0: cmd.append('-%d' % num) @@ -87,7 +86,7 @@ def show_log(state, pathlim, num, full, show_diff): cmd.append('--pretty=tformat:%h %aD %s') cmd.extend([state.sha1, '--']) cmd.extend(pathlim) - Run(*cmd).run() + repository.run(cmd).run() def func(parser, options, args): @@ -115,6 +114,13 @@ def func(parser, options, args): if options.graphical: cmd = ['gitk', state.simplified.sha1, '--'] + pathlim # Discard the exit codes generated by SIGINT, SIGKILL, and SIGTERM. - Run(*cmd).returns([0, -2, -9, -15]).run() + stack.repository.run(cmd).returns([0, -2, -9, -15]).run() else: - show_log(state.simplified, pathlim, options.number, options.full, options.diff) + show_log( + stack.repository, + state.simplified, + pathlim, + options.number, + options.full, + options.diff, + ) diff --git a/t/t0009-log.sh b/t/t0009-log.sh index a76ab68..fbbe431 100755 --- a/t/t0009-log.sh +++ b/t/t0009-log.sh @@ -105,6 +105,18 @@ test_expect_success 'Verify log for p3' ' head -n 3 log.txt | tail -n 1 | grep -e "uncommit" ' +test_expect_success 'Verify log with patch limit from subdir' ' + mkdir subdir && + (cd subdir && + stg log p3 > ../log.txt + ) && + rmdir subdir && + test_line_count = 3 log.txt && + head -n 1 log.txt | tail -n 1 | grep -e "edit" && + head -n 2 log.txt | tail -n 1 | grep -e "goto" && + head -n 3 log.txt | tail -n 1 | grep -e "uncommit" +' + test_expect_success 'Verify log for p2 and p3' ' stg log p2 p3 > log.txt && test_line_count = 5 log.txt && -- 2.11.4.GIT