diff options
-rw-r--r-- | .github/workflows/lintcommit.yml | 2 | ||||
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | scripts/lintcommit.lua | 28 |
3 files changed, 20 insertions, 14 deletions
diff --git a/.github/workflows/lintcommit.yml b/.github/workflows/lintcommit.yml index 71a7ad1462..0bd92c05ec 100644 --- a/.github/workflows/lintcommit.yml +++ b/.github/workflows/lintcommit.yml @@ -16,4 +16,4 @@ jobs: - uses: rhysd/action-setup-vim@v1 with: neovim: true - - run: nvim --clean -l scripts/lintcommit.lua main --notrace + - run: nvim --clean -l scripts/lintcommit.lua main diff --git a/CMakeLists.txt b/CMakeLists.txt index e31c02b640..371112ad73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -259,9 +259,7 @@ add_glob_target( TOUCH_STRATEGY SINGLE) add_custom_target(lintcommit - COMMAND ${PROJECT_BINARY_DIR}/bin/nvim -u NONE -l scripts/lintcommit.lua main --notrace - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - VERBATIM) + COMMAND $<TARGET_FILE:nvim> -u NONE -l ${PROJECT_SOURCE_DIR}/scripts/lintcommit.lua main) add_dependencies(lintcommit nvim) add_custom_target(lint) diff --git a/scripts/lintcommit.lua b/scripts/lintcommit.lua index 7193821afe..d2c8601c25 100644 --- a/scripts/lintcommit.lua +++ b/scripts/lintcommit.lua @@ -1,9 +1,9 @@ -- Usage: -- # verbose --- nvim -l scripts/lintcommit.lua main +-- nvim -l scripts/lintcommit.lua main --trace -- -- # silent --- nvim -l scripts/lintcommit.lua main --notrace +-- nvim -l scripts/lintcommit.lua main -- -- # self-test -- nvim -l scripts/lintcommit.lua _test @@ -13,17 +13,24 @@ local M = {} local _trace = false +-- Print message +local function p(s) + vim.cmd('set verbose=1') + vim.api.nvim_echo({{s, ''}}, false, {}) + vim.cmd('set verbose=0') +end + -- Executes and returns the output of `cmd`, or nil on failure. -- -- Prints `cmd` if `trace` is enabled. local function run(cmd, or_die) if _trace then - print('run: '..vim.inspect(cmd)) + p('run: '..vim.inspect(cmd)) end local rv = vim.trim(vim.fn.system(cmd)) or '' if vim.v.shell_error ~= 0 then if or_die then - print(rv) + p(rv) os.exit(1) end return nil @@ -161,7 +168,7 @@ function M.main(opt) for _, commit_id in ipairs(commits) do local msg = run({'git', 'show', '-s', '--format=%s' , commit_id}) if vim.v.shell_error ~= 0 then - print('Invalid commit-id: '..commit_id..'"') + p('Invalid commit-id: '..commit_id..'"') else local invalid_msg = validate_commit(msg) if invalid_msg then @@ -169,10 +176,10 @@ function M.main(opt) -- Some breathing room if failed == 1 then - print('\n') + p('\n') end - print(string.format([[ + p(string.format([[ Invalid commit message: "%s" Commit: %s %s @@ -185,13 +192,14 @@ Invalid commit message: "%s" end if failed > 0 then - print([[ + p([[ See also: https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages + ]]) os.exit(1) else - print('') + p('') end end @@ -252,7 +260,7 @@ function M._test() local is_valid = (nil == validate_commit(message)) if is_valid ~= expected then failed = failed + 1 - print(string.format('[ FAIL ]: expected=%s, got=%s\n input: "%s"', expected, is_valid, message)) + p(string.format('[ FAIL ]: expected=%s, got=%s\n input: "%s"', expected, is_valid, message)) end end |