diff --git a/mepo.d/cmdline/parser.py b/mepo.d/cmdline/parser.py index e94d1efa..9cb27497 100644 --- a/mepo.d/cmdline/parser.py +++ b/mepo.d/cmdline/parser.py @@ -231,6 +231,7 @@ def __commit(self): commit = self.subparsers.add_parser( 'commit', description = 'Commit staged files in the specified components') + commit.add_argument('-a', '--all', action = 'store_true', help = 'stage all tracked files and then commit') commit.add_argument('-m', '--message', type=str, metavar = 'message', default=None) commit.add_argument( 'comp_name', diff --git a/mepo.d/command/commit/commit.py b/mepo.d/command/commit/commit.py index c9641b2f..7b2ac349 100644 --- a/mepo.d/command/commit/commit.py +++ b/mepo.d/command/commit/commit.py @@ -1,6 +1,7 @@ from state.state import MepoState from utilities import verify from repository.git import GitRepository +from command.stage.stage import stage_files # Popping up an EDITOR is based on https://stackoverflow.com/a/39989442 import os, tempfile, subprocess @@ -26,6 +27,9 @@ def run(args): for comp in comps2commit: git = GitRepository(comp.remote, comp.local) + if args.all: + stage_files(git, comp, commit=True) + staged_files = git.get_staged_files() if staged_files: git.commit_files(args.message,tf_file) diff --git a/mepo.d/command/stage/stage.py b/mepo.d/command/stage/stage.py index b3514143..157016ec 100644 --- a/mepo.d/command/stage/stage.py +++ b/mepo.d/command/stage/stage.py @@ -9,9 +9,17 @@ def run(args): comps2stg = [x for x in allcomps if x.name in args.comp_name] for comp in comps2stg: git = GitRepository(comp.remote, comp.local) - curr_ver = MepoVersion(*git.get_version()) - if curr_ver.detached: # detached head - raise Exception('{} has detached head! Cannot stage.'.format(comp.name)) - for myfile in git.get_changed_files(args.untracked): - git.stage_file(myfile) - print('+ {}: {}'.format(comp.name, myfile)) + stage_files(git, comp, args.untracked) + +def stage_files(git, comp, untracked=False, commit=False): + curr_ver = MepoVersion(*git.get_version()) + if curr_ver.detached: # detached head + raise Exception(f"{comp.name} has detached head! Cannot stage.") + for myfile in git.get_changed_files(untracked): + git.stage_file(myfile) + print_output = f"{comp.name}: {myfile}" + if commit: + print(f"Staged: {print_output}") + else: + print(f"+ {print_output}") + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..14ff6344 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +PyYAML==5.1.2