Skip to content

Commit 5bc6bf6

Browse files
committed
show an error message if user.name or user.email is unset
1 parent 76997d4 commit 5bc6bf6

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

gitless/cli/gl_commit.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,7 @@ def main(args, repo):
5454
if args.p:
5555
partials = _do_partial_selection(commit_files, curr_b)
5656

57-
if not repo.config['user.name']:
58-
pprint.err('Missing name for commit author')
59-
pprint.err_exp('change the value of git\'s user.name setting')
60-
return False
61-
if not repo.config['user.email']:
62-
pprint.err('Missing email for commit author')
63-
pprint.err_exp('change the value of git\'s user.email setting')
57+
if not _author_info_is_ok(repo):
6458
return False
6559

6660
msg = args.m if args.m else commit_dialog.show(commit_files, repo)
@@ -84,6 +78,24 @@ def main(args, repo):
8478
return True
8579

8680

81+
def _author_info_is_ok(repo):
82+
def show_config_error(key):
83+
pprint.err('Missing {0} for commit author'.format(key))
84+
pprint.err_exp('change the value of git\'s user.{0} setting'.format(key))
85+
86+
def config_is_ok(key):
87+
try:
88+
if not repo.config['user.{0}'.format(key)]:
89+
show_config_error(key)
90+
return False
91+
except KeyError:
92+
show_config_error(key)
93+
return False
94+
return True
95+
96+
return config_is_ok('name') and config_is_ok('email')
97+
98+
8799
def _do_partial_selection(files, curr_b):
88100
partials = []
89101
for fp in files:

0 commit comments

Comments
 (0)