Skip to content

Commit

Permalink
detect .git file automatically
Browse files Browse the repository at this point in the history
- configure git to ignore file mode
  • Loading branch information
ichisadashioko committed Sep 11, 2020
1 parent 318be08 commit 122c841
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[core]
filemode=false
17 changes: 13 additions & 4 deletions lf-utf8.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,20 @@ def main():
args = parser.parse_args()
print(args)

file_list = os.listdir(args.infile)

for file_name in file_list:
if file_name == '.git':
args.git = True
break

if args.git:
filepaths = list_git_files(args.infile)
else:
filepaths = find_all_files(args.infile)

for filepath in filepaths:
print('>', filepath)
print('>', filepath, end=' ')

basename = os.path.basename(filepath)
ext = os.path.splitext(basename)[1]
Expand All @@ -202,11 +209,13 @@ def main():
content = content + '\n'
encoded_content = content.encode(Encoding.UTF8)

if encoded_content != bs:
print('>', f'{TermColor.FG_RED}{filepath}{TermColor.RESET_COLOR}', file=sys.stderr)
if encoded_content == bs:
print(f'{TermColor.FG_BRIGHT_GREEN}OK{TermColor.RESET_COLOR}')
else:
print(f'{TermColor.FG_RED}x{TermColor.RESET_COLOR}')

if args.run:
os.remove(filepath) # file will not be changed if we don't remove it
os.remove(filepath) # file content may not be changed if we don't remove it
with open(filepath, mode='wb') as outfile:
outfile.write(encoded_content)

Expand Down

0 comments on commit 122c841

Please sign in to comment.