Skip to content
This repository was archived by the owner on Mar 30, 2026. It is now read-only.

Commit 225dfd5

Browse files
committed
Implement new feature where subgit can now parse up the directory tree until it finds a subgit config file and runs commands from there. This mimics the same feature that git has where if we go into a sub folder that we have cloned out we still want to be able to do operations on it via subgit
Code cleanup and convert all os.path to new PathLib
1 parent 53fc98c commit 225dfd5

3 files changed

Lines changed: 129 additions & 79 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,5 @@ bare/
138138

139139
# Pycharm
140140
.idea/*
141+
code/
142+
_manifest/

subgit/cli.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@
149149

150150

151151
def parse_cli():
152-
"""Parse the CLI arguments and options."""
152+
"""
153+
Parse the CLI arguments and options
154+
"""
153155
import subgit
154156

155157
try:
@@ -222,20 +224,24 @@ def run(cli_args, sub_args):
222224
core = SubGit(
223225
config_file_path=sub_args.get("--conf"),
224226
answer_yes=sub_args.get("--yes"),
225-
hard_flag=sub_args.get("--hard")
226227
)
227228

228229
if cli_args["<command>"] == "fetch":
229230
repos = sub_args["<repo>"]
230231
repos = repos or None
231232

232-
retcode = core.fetch(repos)
233+
retcode = core.fetch(
234+
repos,
235+
)
233236

234237
if cli_args["<command>"] == "init":
235238
repo_name = sub_args["<name>"]
236239
repo_url = sub_args["<url>"]
237240

238-
retcode = core.init_repo(repo_name, repo_url)
241+
retcode = core.init_repo(
242+
repo_name,
243+
repo_url,
244+
)
239245

240246
if cli_args["<command>"] == "pull":
241247
repos = sub_args["<repo>"]
@@ -250,19 +256,25 @@ def run(cli_args, sub_args):
250256
repos = sub_args["<repo>"]
251257
repos = repos or None
252258

253-
retcode = core.delete(repo_names=repos)
259+
retcode = core.delete(
260+
repo_names=repos,
261+
)
254262

255263
if cli_args["<command>"] == "reset":
256264
repos = sub_args["<repo>"]
257265
repos = repos or None
266+
hard_flag = sub_args.get("--hard")
258267

259-
retcode = core.reset(repo_names=repos)
268+
retcode = core.reset(
269+
repo_names=repos,
270+
hard_flag=hard_flag,
271+
)
260272

261273
if cli_args["<command>"] == "import":
262274
git_importer = GitImport(
263275
config_file_name=sub_args.get("--output-file"),
264276
answer_yes=sub_args["--yes"],
265-
is_archived=sub_args.get("--archived")
277+
is_archived=sub_args.get("--archived"),
266278
)
267279
github = sub_args["github"]
268280
gitlab = sub_args["gitlab"]
@@ -282,14 +294,16 @@ def run(cli_args, sub_args):
282294
repo_names=repos,
283295
recurse_into_dir=sub_args.get("-d"),
284296
force=sub_args.get("--force"),
285-
dry_run=sub_args.get("--dry-run")
297+
dry_run=sub_args.get("--dry-run"),
286298
)
287299

288300
return retcode
289301

290302

291303
def cli_entrypoint():
292-
"""Used by setup.py to create a cli entrypoint script."""
304+
"""
305+
Used by setup.py to create a cli entrypoint script
306+
"""
293307
try:
294308
cli_args, sub_args = parse_cli()
295309
exit_code = run(cli_args, sub_args)
@@ -300,8 +314,10 @@ def cli_entrypoint():
300314
if "DEBUG" in os.environ:
301315
extype, value, tb = sys.exc_info()
302316
traceback.print_exc()
317+
303318
if "PDB" in os.environ:
304319
pdb.post_mortem(tb)
320+
305321
raise
306322
else:
307323
print(f"Exception type : {ex_type.__name__}")

0 commit comments

Comments
 (0)