From 904eb242814aeced2031753288cb312c0d91d6a4 Mon Sep 17 00:00:00 2001 From: "Kenneth M. Elf Sternberg" Date: Thu, 22 Sep 2016 15:50:01 -0700 Subject: [PATCH] A few more updates. Added new flags to usage. --- docs/modules.rst | 7 +++++ docs/usage.rst | 64 +++++++++++++++++++++------------------- git_lint_src/git_lint.hy | 28 +++++++++++++++--- 3 files changed, 64 insertions(+), 35 deletions(-) create mode 100644 docs/modules.rst diff --git a/docs/modules.rst b/docs/modules.rst new file mode 100644 index 0000000..1e0bad5 --- /dev/null +++ b/docs/modules.rst @@ -0,0 +1,7 @@ +git_lint +======== + +.. toctree:: + :maxdepth: 4 + + git_lint diff --git a/docs/usage.rst b/docs/usage.rst index 4390577..fd5863d 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -11,42 +11,42 @@ git lint [options] [filenames] Options ------- - -``-h`` ``--help`` - Help - -``-v`` ``--version`` - Version info - -``-c`` ``--config`` - Specify config file (default: ``$GIT_DIR/.git-lint``) - -``-w`` ``--workspace`` - Check workspace [default] - -``-s`` ``--staging`` - Check files in the staging area (useful as a pre-commit hook) - -``-b`` ``--base`` - Run checks from your repository's root directory. By default, - ``git-lint`` only runs from the current working directory. - -``-a`` ``--all`` - Check all files in repository from the current directory, not - just changed files - -``-e`` ``--everything`` - An alias for ``-b -a``, checks every file in the repository - ``-o`` ``--only`` - Run only specific linters, skipping all others - -``-e`` ``--exclude`` - Exclude specific linters, running all others + A comma-separated list of only those linters to run +``-x`` ``--exclude`` + A comma-separated list of linters to skip +``-l`` ``--linters`` + Show the list of configured linters +``-b`` ``--base`` + Check all changed files in the repository, not just those in the current directory. +``-a`` ``--all`` + Scan all files in the repository, not just those that have changed. +``-e`` ``--every`` + Short for -b -a: scan everything +``-w`` ``--workspace`` + Scan the workspace +``-s`` ``--staging`` + Scan the staging area (useful for pre-commit). +``-g`` ``--changes`` + Report lint failures only for diff'd sections +``-p`` ``--complete`` + Report lint failures for all files +``-c`` ``--config`` + Path to config file +``-d`` ``--dryrun`` + Report what git-lint would do, but don't actually do anything. +``-q`` ``--quiet`` + Produce a short report of files that failed to pass. +``-h`` ``--help`` + This help message +``-v`` ``--version`` + Version information As a pre-commit hook: --------------------- +.. code-block:: python + #!/usr/bin/env python import git_lint git_lint.run_precommit(staging = True, timestamps = True) @@ -54,6 +54,8 @@ As a pre-commit hook: Install this file in your project's ``.git/hooks/pre-commit``, and set the file's executable flag to ``true``: +.. code-block:: shell + chmod +x pre-commit Please see the :ref:`api` for more details on options taken by the diff --git a/git_lint_src/git_lint.hy b/git_lint_src/git_lint.hy index 0a139cb..50c9667 100644 --- a/git_lint_src/git_lint.hy +++ b/git_lint_src/git_lint.hy @@ -37,10 +37,6 @@ (defn split-git-response [cmd] (let [[(, out error returncode) (get-git-response-raw cmd)]] (.splitlines out))) -(defn split-git-response [cmd] - (let [[(, out error returncode) (get-git-response-raw cmd)]] (.splitlines out))) - - (defn run-git-command [cmd] (let [[fullcmd (+ ["git"] cmd)]] (subprocess.call fullcmd @@ -67,6 +63,30 @@ [(, out err returncode) (get-git-response-raw ["rev-parse" "--verify HEAD"])]] (if (not err) "HEAD" empty-repository-hash))) + +(defn run-external-checker [filename check] + (let [[cmd (-> (get check "command") + (.format + :filename filename + :config_path *config-path*))] + [(, out err returncode) (get-shell-response cmd)]] + (if (or (and out (= (.get check "error_condition" "error") "output")) + err + (not (= returncode 0))) + (let [[prefix (if (get check "print_filename") + (.format "\t{}:" filename) + "\t")] + [output (+ (encode-shell-messages prefix out) + (if err (encode-shell-messages prefix err) []))]] + [(or returncode 1) output]) + [0 []]))) + +; ___ _ _ ___ _ _ ___ _ _ +;| __(_) |___ _ _ __ _ _ __ ___ | __|_ _| |_ ___ _ _ __(_)___ _ _ / __| |_ ___ __| |__ +;| _|| | / -_) ' \/ _` | ' \/ -_) | _|\ \ / _/ -_) ' \(_-< / _ \ ' \ | (__| ' \/ -_) _| / / +;|_| |_|_\___|_||_\__,_|_|_|_\___| |___/_\_\\__\___|_||_/__/_\___/_||_| \___|_||_\___\__|_\_\ +; + (defn make-match-filter-matcher [extensions] (->> (map (fn [s] (.split s ",")) extensions) (reduce operator.add)