]> granicus.if.org Git - esp-idf/commitdiff
ci: Add line endings check for CRLF in repository
authorAngus Gratton <angus@espressif.com>
Fri, 23 Mar 2018 06:05:16 +0000 (17:05 +1100)
committerIvan Grokhotkov <ivan@espressif.com>
Thu, 12 Jul 2018 11:10:37 +0000 (19:10 +0800)
.gitlab-ci.yml
docs/en/contribute/style-guide.rst
tools/ci/check-line-endings.sh [new file with mode: 0755]
tools/ci/executable-list.txt

index 1ec6dfa1d7283b2d4823d8e71991b0c207d578d3..8a44f5bd7fa571b753904f7c9dfb74aba950cbe5 100644 (file)
@@ -431,6 +431,20 @@ check_doc_links:
     - cd docs
     - make linkcheck
 
+check_line_endings:
+  stage: deploy
+  image: $CI_DOCKER_REGISTRY/esp32-ci-env$BOT_DOCKER_IMAGE_TAG
+  tags:
+    - build
+  except:
+    - master
+    - /^release\/v/
+    - /^v\d+\.\d+(\.\d+)?($|-)/
+  dependencies: []
+  before_script: *do_nothing_before
+  script:
+    - tools/ci/check-line-endings.sh ${IDF_PATH}
+
 check_commit_msg:
   stage: deploy
   image: $CI_DOCKER_REGISTRY/esp32-ci-env$BOT_DOCKER_IMAGE_TAG
index 6564bd0832975a2322a529c0406e2823711d5b64..9eb10e892107bf7cf949c952ebd3f4f124b3916a 100644 (file)
@@ -158,6 +158,21 @@ Although not directly related to formatting, here are a few notes about using co
     }
 
 
+Line Endings
+^^^^^^^^^^^^
+
+Commits should only contain files with LF (Unix style) endings.
+
+Windows users can configure git to check out CRLF (Windows style) endings locally and commit LF endings by setting the ``core.autocrlf`` setting. `Github has a document about setting this option <github-line-endings>`. However because MSYS2 uses Unix-style line endings, it is often easier to configure your text editor to use LF (Unix style) endings when editing ESP-IDF source files.
+
+If you accidentally have some commits in your branch that add LF endings, you can convert them to Unix by running this command in an MSYS2 or Unix terminal (change directory to the IDF working directory and check the correct branch is currently checked out, beforehand)::
+
+  git rebase --exec 'git diff-tree --no-commit-id --name-only -r HEAD | xargs dos2unix && git commit -a --amend --no-edit --allow-empty' master
+
+(Note that this line rebases on master, change the branch name at the end to rebase on another branch.)
+
+For updating a single commit, it's possible to run ``dos2unix FILENAME`` and then run ``git commit --amend``
+
 Formatting your code
 ^^^^^^^^^^^^^^^^^^^^
 
diff --git a/tools/ci/check-line-endings.sh b/tools/ci/check-line-endings.sh
new file mode 100755 (executable)
index 0000000..b813aa6
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+if ! [ -z "$1" ]; then
+    cd "$1"
+fi
+
+echo "Checking for Windows line endings in `pwd`"
+
+if git ls-tree --name-only -r HEAD | xargs file -N | grep CRLF; then
+    echo "Some files have CRLF (Windows-style) line endings. Please convert to LF (Unix-style). git can be configured to do this automatically."
+    exit 1
+fi
+
+exit 0
index 989c31b17c544a4aed38ab72ae6de394b4f16cbe..74ff88c10d0e468baeae10d89e290c6a98114501 100644 (file)
@@ -14,6 +14,7 @@ docs/gen-kconfig-doc.py
 tools/ci/apply_bot_filter.py
 tools/ci/build_examples.sh
 tools/ci/check-executable.sh
+tools/ci/check-line-endings.sh
 tools/ci/checkout_project_ref.py
 tools/ci/get-full-sources.sh
 tools/ci/mirror-submodule-update.sh