@@ -31,8 +31,20 @@ class SubGit():
3131
3232 def __init__ (self , config_file_path = None , answer_yes = False ):
3333 self .answer_yes = answer_yes
34+ self .config_file_path = config_file_path
3435
35- if not config_file_path :
36+ if config_file_path :
37+ self .subgit_config_file_name = Path (config_file_path ).name
38+ self .subgit_config_file_path = Path (config_file_path ).resolve ()
39+ else :
40+ self .subgit_config_file_name = ".subgit.yml"
41+ self .subgit_config_file_path = Path .cwd () / ".subgit.yml"
42+
43+ def _get_recursive_config_path (self ):
44+ """
45+ Looks for either .sgit.yml or .subgit.yml recursively
46+ """
47+ if not self .config_file_path :
3648 # Get the CWD where you execute the script from
3749 path = Path ().cwd ()
3850
@@ -65,15 +77,16 @@ def __init__(self, config_file_path=None, answer_yes=False):
6577 log .debug (self .subgit_config_file_name )
6678 log .debug (self .subgit_config_file_path )
6779 else :
68- self .subgit_config_file_name = Path (config_file_path ).name
69- self .subgit_config_file_path = Path (config_file_path ).resolve ()
80+ self .subgit_config_file_name = Path (self . config_file_path ).name
81+ self .subgit_config_file_path = Path (self . config_file_path ).resolve ()
7082
7183 def init_repo (self , repo_name = None , repo_url = None ):
7284 """
7385 If repo_name & repo_url is set to a string value, it will be attempted to be added to the initial
7486 .subgit.yml config file as the first repo in your config. If these values is anything else the initial
7587 config vill we written as empty.
7688 """
89+
7790 if self .subgit_config_file_path .exists ():
7891 log .error (f"File '{ self .subgit_config_file_name } ' already exists on disk" )
7992 return 1
@@ -115,6 +128,7 @@ def _dump_config_file(self, config_data):
115128 )
116129
117130 def repo_status (self ):
131+ self ._get_recursive_config_path ()
118132 config = self ._get_config_file ()
119133 repos = config .get ("repos" , {})
120134
@@ -244,6 +258,8 @@ def fetch(self, repos):
244258
245259 A empty list of items will not fetch any repo.
246260 """
261+ self ._get_recursive_config_path ()
262+
247263 log .debug (f"repo fetch input - { repos } " )
248264
249265 config = self ._get_config_file ()
@@ -315,6 +331,8 @@ def pull(self, names):
315331
316332 To pull a subset of repos send in a list of strings names=["repo1", "repo2"]
317333 """
334+ self ._get_recursive_config_path ()
335+
318336 log .debug (f"Repo pull - { names } " )
319337
320338 config = self ._get_config_file ()
@@ -554,6 +572,7 @@ def delete(self, repo_names=None):
554572 more of them creates a conflict. (e.g repo(s) is not in the config file,
555573 path(s) is not to a valid git repo or repo(s) is dirty)
556574 """
575+ self ._get_recursive_config_path ()
557576 has_dirty_repos = False
558577 good_repos = []
559578 repos_dict = self ._get_repos (repo_names )
@@ -587,6 +606,7 @@ def reset(self, repo_names=None, hard_flag=None):
587606 Will take a list of repos and find any diffs and reset them back
588607 to the same state they were when they were first pulled.
589608 """
609+ self ._get_recursive_config_path ()
590610 dirty_repos = []
591611 repos_dict = self ._get_repos (repo_names )
592612 repos = repos_dict ["repos" ]
@@ -626,6 +646,7 @@ def clean(self, repo_names=None, recurse_into_dir=None, force=None, dry_run=None
626646 """
627647 Method to look through a list of repos and remove untracked files
628648 """
649+ self ._get_recursive_config_path ()
629650 dirty_repos = []
630651 recursive_flag = "d" if recurse_into_dir else ""
631652 force_flag = "f" if force else ""
0 commit comments