From 65e6a0abdeed2d38841b7db8b246068e84059065 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 8 May 2023 21:11:34 -0700 Subject: [PATCH] Add ability to check if files are untracked and add them to the git repo. --- coder.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/coder.py b/coder.py index 00b966df3..8a6a344b2 100755 --- a/coder.py +++ b/coder.py @@ -87,7 +87,16 @@ class Coder: self.console.print("[red bold]Files are in different git repos, can't commit edits to allow easy undo") return - # todo: need to check if files are added to the repo, and add if not + for fname in self.fnames: + relative_fname = os.path.relpath(fname, self.repo.working_tree_dir) + if relative_fname not in self.repo.untracked_files: + continue + question = f"[red bold]Add {fname} to the git repo?" + if Confirm.ask(question, console=self.console): + self.repo.git.add(relative_fname) + self.console.print(f"[red]Added {fname} to the git repo") + else: + self.console.print(f"[red]Skipped adding {fname} to the git repo") self.repo = git.Repo(repo_paths.pop())