Skip to content

Commit

Permalink
Merge pull request #137 from GEOS-ESM/develop
Browse files Browse the repository at this point in the history
Merge Develop into main for 'commit -a'
  • Loading branch information
tclune authored Nov 20, 2020
2 parents 13651a2 + caed0f9 commit 78eaaee
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions mepo.d/cmdline/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions mepo.d/command/commit/commit.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
20 changes: 14 additions & 6 deletions mepo.d/command/stage/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PyYAML==5.1.2

0 comments on commit 78eaaee

Please sign in to comment.