Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --skip-submodules argument #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
18 changes: 16 additions & 2 deletions clustergit
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ def read_arguments(args: List[str]) -> argparse.Namespace:
help="Skip symbolic links when searching for git repos"
)

parser.add_argument(
"--skip-submodules",
action="store_true",
dest="skip_submodules",
default=False,
help="Skip git submodules"
)

parser.add_argument(
"-e", "--exclude",
action="append",
Expand Down Expand Up @@ -522,15 +530,21 @@ def scan(dirpath: str, dirnames: List[str], options: argparse.Namespace) -> List
print(f'skipping {path}')
return False

# Remove if is there a .clustergit-ignore file
# Remove if there is a .clustergit-ignore file
if os.path.exists(os.path.join(path, ".clustergit-ignore")):
if options.verbose:
print(f'skipping {path} directory')
return False

# Remove if there is no .git dir
if os.path.exists(os.path.join(path, ".git")):
if options.skip_submodules:
if os.path.isfile(os.path.join(path, ".git")):
# Remove if there is a .git file (we are inside a git submodule)
if options.verbose:
print(f'skipping {path} git submodule')
return False
if options.skipSymLinks and os.path.islink(path):
# Remove if there is no .git dir
if options.verbose:
print(f'skipping {path} symbolic link')
return False
Expand Down
15 changes: 7 additions & 8 deletions tests/tests/clustergit_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from tools import same
from .tools import same

from cStringIO import StringIO
from io import StringIO
import sys
import tempfile

Expand All @@ -17,12 +17,11 @@ def test_check_no_repo(self):
clustergit.main([])

actual_out = mystdout.getvalue()
expected_out = """Starting git status...
Scanning sub directories of .
expected_out = """Scanning sub directories of ['.']

"""
actual_err = mystderr.getvalue()
expected_err = """Error: None of those sub directories had a .git file.
expected_err = """Error: None of those sub directories had a .git file
"""
same("stdout should be alright", expected_out, actual_out)
same("stderr should be alright", expected_err, actual_err)
Expand All @@ -34,7 +33,7 @@ def test_check_no_repo(self):

def test_check_fresh_repo(self):
dirpath = tempfile.mkdtemp()
print "working in %s" % (dirpath)
print("working in %s" % (dirpath))
clustergit.run('cd "%s"; mkdir mygit; cd mygit; git init' % (dirpath), clustergit.read_arguments(['-v']))

old_stdout = sys.stdout
Expand Down Expand Up @@ -62,7 +61,7 @@ def test_check_fresh_repo(self):

def test_excluded(self):
dirpath = tempfile.mkdtemp()
print "working in %s" % (dirpath)
print("working in %s" % (dirpath))
out = clustergit.run(
'cd "%s";' % (dirpath)
+ 'mkdir notarepo repo1 repo2 target;'
Expand All @@ -71,7 +70,7 @@ def test_excluded(self):
+ 'tree -A', # show structure in error messages
clustergit.read_arguments(['-v'])
)
print out
print(out)

old_stdout = sys.stdout
old_stderr = sys.stderr
Expand Down