diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 89bf73b..766eb76 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -8,6 +8,7 @@ The format is based on `Keep a Changelog `
[unreleased]
------------
+- Rather than opening text editor for commit message, allow user to provide custom message as command line arg; changes name of command line arg to 'commit_message' from 'custom_message' (@kcranston, #466)
- Remove docs build on python 3.6 - sphinx template no longer supports 3.6, add build for 3.9 (@lwasser, #481)
- Cleanup old requirements and directories (@lwasser, #415)
- Update documentation to discuss using extra_files to modify gitignore and readme (@lwasser, #178)
diff --git a/abcclassroom/__main__.py b/abcclassroom/__main__.py
index 790a8d2..9c3fdbf 100644
--- a/abcclassroom/__main__.py
+++ b/abcclassroom/__main__.py
@@ -136,11 +136,10 @@ def new_template():
course_materials/release directory""",
)
parser.add_argument(
- "--custom-message",
- action="store_true",
- help="""Use a custom commit message for git. Will open the default
- git text editor for entry (if not set, uses default message 'Initial
- commit').""",
+ "--commit-message",
+ default="Initial commit",
+ help="""Enter a commit message for git. If not set, uses default
+ message 'Initial commit').""",
)
parser.add_argument(
"--github",
@@ -159,7 +158,6 @@ def new_template():
(Default = fail).""",
)
args = parser.parse_args()
-
template.new_update_template(args)
@@ -220,9 +218,14 @@ def update_template():
directory); merge = overwrite existing files add new files
(Default = merge).""",
)
+ parser.add_argument(
+ "--commit-message",
+ default="Updating assignment",
+ help="""Enter a commit message for git. If not set, uses default
+ message 'Updating assignment').""",
+ )
args = parser.parse_args()
# now set the additional args (so that it matches the keys in add_template
# and we can use the same implementation methods)
setattr(args, "github", True)
- setattr(args, "custom_message", True)
template.new_update_template(args)
diff --git a/abcclassroom/git.py b/abcclassroom/git.py
index 0cf8853..ded107b 100644
--- a/abcclassroom/git.py
+++ b/abcclassroom/git.py
@@ -7,9 +7,6 @@
# methods that involve the GitHub API
import subprocess
-import sys
-
-from .utils import input_editor
def check_git_ssh():
@@ -134,22 +131,6 @@ def repo_changed(directory):
return bool(ret.stdout)
-def get_commit_message():
- default_message = """
- # Please enter the commit message for your changes. Lines starting
- # with '#' will be ignored, and an empty message aborts the commit.
- # This message will be used as commit and Pull Request message."""
- message = input_editor(default_message)
- message = "\n".join(
- [
- line
- for line in message.split("\n")
- if not line.strip().startswith("#")
- ]
- )
- return message
-
-
def commit_all_changes(directory, msg=None):
"""Run git add, git commit on a given directory. Checks git status
first and does nothing if no changes.
@@ -163,7 +144,7 @@ def commit_all_changes(directory, msg=None):
print("No changes in repository {}; doing nothing".format(directory))
-def init_and_commit(directory, custom_message=False):
+def init_and_commit(directory, commit_message):
"""Run git init, git add, git commit on given directory. Checks git status
first and does nothing if no changes are detected.
@@ -187,13 +168,7 @@ def init_and_commit(directory, custom_message=False):
git_init(directory)
_master_branch_to_main(directory)
if repo_changed(directory):
- message = "Initial commit"
- if custom_message:
- message = get_commit_message()
- if not message:
- print("Empty commit message, exiting.")
- sys.exit(1) # sys is undefined - ask karen about this
- commit_all_changes(directory, message)
+ commit_all_changes(directory, commit_message)
else:
print("No changes to local repository.")
diff --git a/abcclassroom/template.py b/abcclassroom/template.py
index 56a8885..35978aa 100644
--- a/abcclassroom/template.py
+++ b/abcclassroom/template.py
@@ -34,7 +34,7 @@ def new_update_template(args):
create_template(
mode=args.mode,
push_to_github=args.github,
- custom_message=args.custom_message,
+ commit_message=args.commit_message,
assignment_name=args.assignment,
)
except FileNotFoundError as fnfe:
@@ -46,7 +46,10 @@ def new_update_template(args):
def create_template(
- assignment_name, mode="fail", push_to_github=False, custom_message=False
+ assignment_name,
+ mode="fail",
+ push_to_github=False,
+ commit_message="Initial commit",
):
"""
Classroom package function that creates or updates an assignment template
@@ -70,8 +73,10 @@ def create_template(
push_to_github : boolean
True if you want to push to GH
mode : merge, fail
- custom message : boolean (default = False)
- True if you want to push to github.
+ commit_message : string
+ Sets a custom git commit message. For new templates, default is
+ "Initial commit" and for updating templates, default is
+ "Updating assignment"
assignment_name : string
name of the assignment
"""
@@ -97,7 +102,7 @@ def create_template(
except FileNotFoundError as e:
print(e)
raise FileNotFoundError(
- "Oops, it looks like the assignment - {} - does not exist"
+ "Oops, it looks like the assignment - {} - does not exist "
"in the location that I expected it: \n{}. \nDid "
"you spell the assignment name correctly and is there a "
"directory at this path?".format(assignment_name, release_path)
@@ -112,7 +117,7 @@ def create_template(
)
# Create the local git repository and commit changes
- abcgit.init_and_commit(template_repo_path, custom_message)
+ abcgit.init_and_commit(template_repo_path, commit_message)
# Create / append assignment entry in config - this should only happen if
# the assignment above exists...
diff --git a/abcclassroom/tests/test_assignment_template.py b/abcclassroom/tests/test_assignment_template.py
index b49681c..665f4ca 100644
--- a/abcclassroom/tests/test_assignment_template.py
+++ b/abcclassroom/tests/test_assignment_template.py
@@ -20,9 +20,7 @@ def test_create_template(course_structure_assignment):
course_dir = Path(config["course_directory"])
templates_dir = Path(config["template_dir"])
- abctemplate.create_template(
- assignment_name, push_to_github=False, custom_message=False
- )
+ abctemplate.create_template(assignment_name, push_to_github=False)
expected_template_dir = Path(
course_dir, templates_dir, "{}-template".format(assignment_name)
@@ -40,9 +38,32 @@ def test_create_template_no_assignment(sample_course_structure):
with pytest.raises(
FileNotFoundError, match="Oops, it looks like the assignment"
):
- abctemplate.create_template(
- "assignment_test", push_to_github=False, custom_message=False
- )
+ abctemplate.create_template("assignment_test", push_to_github=False)
+
+
+def test_create_custom_commit_message(course_structure_assignment):
+ """
+ Test that top-level create_template uses a custom commit message
+ if provided.
+ """
+ config, assignment_name, release_path = course_structure_assignment
+ course_dir = Path(config["course_directory"])
+ templates_dir = Path(config["template_dir"])
+
+ abctemplate.create_template(
+ assignment_name,
+ mode="delete",
+ push_to_github=False,
+ commit_message="Custom commit message",
+ )
+
+ expected_template_dir = Path(
+ course_dir, templates_dir, "{}-template".format(assignment_name)
+ )
+ assert expected_template_dir.exists()
+
+ git_return = abcgit._call_git("log", directory=expected_template_dir)
+ assert "Custom commit" in git_return.stdout
def test_create_template_dir(course_structure_assignment):
@@ -132,7 +153,7 @@ def test_create_template_dir_move_git_dir(course_structure_assignment):
# create a file in the template dir, init a git repo and commit
testfile = Path(template_path, "file1.txt")
testfile.touch()
- abcgit.init_and_commit(template_path, False)
+ abcgit.init_and_commit(template_path, "commit message")
assert Path(template_path, ".git").exists()
template_path = abctemplate.create_template_dir(
diff --git a/abcclassroom/tests/test_git.py b/abcclassroom/tests/test_git.py
index 023dd14..93053e6 100644
--- a/abcclassroom/tests/test_git.py
+++ b/abcclassroom/tests/test_git.py
@@ -13,7 +13,8 @@ def test_init_and_commit(default_config, tmp_path):
repo_dir.mkdir()
a_file = Path(repo_dir, "testfile.txt")
a_file.write_text("Some text")
- abcgit.init_and_commit(repo_dir)
+ commit_message = "changing some things"
+ abcgit.init_and_commit(repo_dir, commit_message)
assert Path(repo_dir, ".git").exists()
git_return = abcgit._call_git("log", directory=repo_dir)
assert git_return.stdout.startswith("commit")
diff --git a/docs/api/abcclassroom.auth.rst b/docs/api/abcclassroom.auth.rst
new file mode 100644
index 0000000..1da142c
--- /dev/null
+++ b/docs/api/abcclassroom.auth.rst
@@ -0,0 +1,4 @@
+.. automodule:: abcclassroom.auth
+ :members:
+ :undoc-members:
+ :show-inheritance:
diff --git a/docs/api/abcclassroom.git.rst b/docs/api/abcclassroom.git.rst
new file mode 100644
index 0000000..3e199a9
--- /dev/null
+++ b/docs/api/abcclassroom.git.rst
@@ -0,0 +1,4 @@
+.. automodule:: abcclassroom.git
+ :members:
+ :undoc-members:
+ :show-inheritance:
diff --git a/docs/api/abcclassroom.rst b/docs/api/abcclassroom.rst
index b9b9909..97724cc 100644
--- a/docs/api/abcclassroom.rst
+++ b/docs/api/abcclassroom.rst
@@ -12,9 +12,11 @@ Submodules
.. toctree::
:maxdepth: 4
+ abcclassroom.auth
abcclassroom.clone
abcclassroom.config
abcclassroom.feedback
+ abcclassroom.git
abcclassroom.github
abcclassroom.quickstart
abcclassroom.roster
diff --git a/docs/manage-assignments/new_assignment.rst b/docs/manage-assignments/new_assignment.rst
index be205e5..fc6fce7 100644
--- a/docs/manage-assignments/new_assignment.rst
+++ b/docs/manage-assignments/new_assignment.rst
@@ -113,23 +113,13 @@ A few notes about how this works:
Text Editors and Git Commit Messages
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The default commit message used when you run
-``abc-new-template `` is **initial commit**. A text editor
-will not open in this case.
+``abc-new-template `` is "Initial commit". For
+``abc-update-template`` the default message is "Updating assignment".
-When you run ``abc-update-template`` the text editor that is specified in your
-system configuration settings will open up. If you do not have a text editor
-specified, VIM will open as a default.
+If you want to provide a custom commit message, use the ``--commit-message``
+flag with either script, and provide a message after the flag, e.g.::
-If you wish to use nano instead you can run the following in your terminal::
-
- export EDITOR=nano
-
-.. note::
- Right now if you try to use an editor like atom that launches outside of the
- terminal, abc-classroom will currently fail and return a message saying
- **empty commit message** . This may be fixed in the future but for now we
- suggest that you use a terminal based editor for your default when using
- abc-classroom.
+ abc-update-template assignment1 --commit-message "adding new notebook"
@@ -153,8 +143,7 @@ Run ``abc-new-template -h`` to see the options. The output is reproduced below::
optional arguments:
-h, --help show this help message and exit
- --custom-message Use a custom commit message for git. Will open the
- default git text editor for entry (if not set, uses
+ --commit-message Provide a custom commit message for git (if not set, uses
default message 'Initial commit').
--github Also perform the GitHub operations (create remote repo
on GitHub and push to remote (by default, only does
@@ -201,6 +190,8 @@ is reproduced here::
optional arguments:
-h, --help show this help message and exit
+ --commit-message Provide a custom commit message for git (if not set, uses
+ default message 'Updating assignment').
--mode {delete,merge}
What to do with existing contents of template
directory. Choices are: delete = remove contents