Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
/dist/
/htmlcov/
/test/stage/
.venv
.idea
1 change: 1 addition & 0 deletions mike/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def deploy(cfg, version, title=None, aliases=[], update_aliases=False,
for f in git_utils.walk_real_files(cfg['site_dir']):
canonical_file = f.copy(destdir, cfg['site_dir'])
commit.add_file(canonical_file)
print(f"Adding {f.path}")
for d in alias_destdirs:
alias_file = f.copy(d, cfg['site_dir'])
if alias_type == AliasType.redirect:
Expand Down
21 changes: 18 additions & 3 deletions mike/git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import unicodedata

from enum import Enum
from gitignore_parser import parse_gitignore

BranchStatus = Enum('BranchState', ['even', 'ahead', 'behind', 'diverged'])

Expand Down Expand Up @@ -316,8 +317,8 @@ def finish(self):
if self._pipe.wait() != 0:
raise GitCommitError(self._stderr.decode('utf-8'))

if ( not self._allow_empty
and is_commit_empty(get_latest_commit(self._branch)) ):
if (not self._allow_empty
and is_commit_empty(get_latest_commit(self._branch))):
delete_latest_commit(self._branch)
raise GitEmptyCommit()

Expand Down Expand Up @@ -407,13 +408,27 @@ def walk_files(branch, path=''):
.format(branch=branch, path=gpath))


def walk_real_files(srcdir):
def walk_real_files(srcdir, topdir=os.getcwd()):
gitignorepath=os.path.join(topdir,'.gitignore')
gitignore = parse_gitignore(gitignorepath) if os.path.isfile(gitignorepath) else None
if gitignore is not None:
print(f"Using Gitignore: {gitignorepath}")
for path, dirs, filenames in os.walk(srcdir):
# if gitignore is not None:
# if gitignore(path) is True:
# print(f"Ignoring: {path}",file=sys.stderr)
# continue
if '.git' in dirs:
dirs.remove('.git')
for f in filenames:

filepath = os.path.join(path, f)
if gitignore is not None:
if gitignore(filepath) is True:
print(f"Ignoring: {path}",file=sys.stderr)
continue
mode = 0o100755 if os.access(filepath, os.X_OK) else 0o100644
with open(filepath, 'rb') as fd:
data = fd.read()

yield FileInfo(filepath, data, mode)
22 changes: 22 additions & 0 deletions requirments.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
click==8.2.1
ghp-import==2.1.0
gitignore_parser==0.1.13
importlib_metadata==8.7.0
importlib_resources==6.5.2
Jinja2==3.1.6
Markdown==3.8.2
MarkupSafe==3.0.2
mergedeep==1.3.4
mkdocs==1.6.1
mkdocs-get-deps==0.2.0
packaging==25.0
pathspec==0.12.1
platformdirs==4.4.0
pyparsing==3.2.3
python-dateutil==2.9.0.post0
PyYAML==6.0.2
pyyaml_env_tag==1.1
six==1.17.0
verspec==0.1.0
watchdog==6.0.0
zipp==3.23.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def run(self):

install_requires=(['importlib_metadata', 'importlib_resources',
'jinja2 >= 2.7', 'mkdocs >= 1.0', 'pyparsing >= 3.0',
'pyyaml >= 5.1', 'pyyaml_env_tag', 'verspec']),
'pyyaml >= 5.1', 'pyyaml_env_tag', 'verspec', 'gitignore-parser>= 0.1.13 ']),
extras_require={
'dev': ['coverage', 'flake8 >= 3.0', 'flake8-quotes', 'shtab'],
'test': ['coverage', 'flake8 >= 3.0', 'flake8-quotes', 'shtab'],
Expand Down
1 change: 1 addition & 0 deletions test/data/directory_ignored/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file.txt
1 change: 1 addition & 0 deletions test/data/directory_ignored/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello there
15 changes: 11 additions & 4 deletions test/unit/test_git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,15 +796,22 @@ def test_nonexistent(self):
class TestWalkRealFiles(unittest.TestCase):
mode = 0o100755 if sys.platform == 'win32' else 0o100644

def setUp(self):
self.directory = os.path.join(test_data_dir, 'directory')

def test_walk(self):
files = sorted(git_utils.walk_real_files(self.directory),
self.directory = os.path.join(test_data_dir, 'directory')
files = sorted(git_utils.walk_real_files(self.directory, self.directory),
key=lambda x: x.path)

path = os.path.join(self.directory, 'file.txt')
with open(path, 'rb') as f:
data = f.read()

self.assertEqual(files, [git_utils.FileInfo(path, data, self.mode)])

def test_walk_ignore(self):
self.directory = os.path.join(test_data_dir, 'directory_ignored')
files = sorted(git_utils.walk_real_files(self.directory, self.directory),
key=lambda x: x.path)
path = os.path.join(self.directory, '.gitignore')
with open(path, 'rb') as f:
data = f.read()
self.assertEqual(files,[git_utils.FileInfo(path, data, self.mode)])