From 679103795b9d58ea6ee79f75c8404e85c6ecabb5 Mon Sep 17 00:00:00 2001 From: Johan Henkens Date: Wed, 5 Dec 2018 09:23:54 -0800 Subject: [PATCH] Add dos2unix plugin --- README.md | 2 ++ plugins/dos2unix/README.md | 9 +++++++++ plugins/dos2unix/__init__.py | 11 +++++++++++ 3 files changed, 22 insertions(+) create mode 100644 plugins/dos2unix/README.md create mode 100644 plugins/dos2unix/__init__.py diff --git a/README.md b/README.md index bb5815d..b808d88 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,8 @@ class Filter: #Or don't pass, if you want to do some init code here ``` +Beyond the boilerplate initialization, you can see the one of the +defined filter methods in the [dos2unix](./plugins/dos2unix) plugin. ``` commit_data = {'branch': branch, 'parents': parents, 'author': author, 'desc': desc} diff --git a/plugins/dos2unix/README.md b/plugins/dos2unix/README.md new file mode 100644 index 0000000..5f35f11 --- /dev/null +++ b/plugins/dos2unix/README.md @@ -0,0 +1,9 @@ +## Dos2unix filter + +This plugin converts CRLF line ending to LF in text files in the repo. +It is recommended that you have a .gitattributes file that maintains +the usage of LF endings going forward, for after you have converted your +repository. + +To use the plugin, add +`--plugin dos2unix`. diff --git a/plugins/dos2unix/__init__.py b/plugins/dos2unix/__init__.py new file mode 100644 index 0000000..bf676a0 --- /dev/null +++ b/plugins/dos2unix/__init__.py @@ -0,0 +1,11 @@ +def build_filter(args): + return Filter(args) + +class Filter(): + def __init__(self, args): + pass + + def file_data_filter(self,file_data): + file_ctx = file_data['file_ctx'] + if not file_ctx.isbinary(): + file_data['data'] = file_data['data'].replace('\r\n', '\n') -- 2.11.4.GIT