add a "commit" handler to rstrip commit messages
This commit is contained in:
parent
a970a6ef8a
commit
ab839658ba
3
README
3
README
@ -49,6 +49,9 @@ Implemented subcommands:
|
||||
actually remove them
|
||||
-f, --force
|
||||
- perform the actual removal of unversioned files
|
||||
commit
|
||||
- removes trailing whitespace (including end-of-line characters) from commit
|
||||
messages before committing if neither -m nor -F arguments are given
|
||||
diff
|
||||
- allow specifying ref1..ref2 syntax to show the diff between two references
|
||||
- references can be tag names, branch names, or 'trunk'
|
||||
|
44
jsvn
44
jsvn
@ -20,6 +20,7 @@ import tempfile
|
||||
import shutil
|
||||
|
||||
STATUS_LINE_REGEX = r'[ACDIMRX?!~ ][CM ][L ][+ ][SX ][KOTB ]..(.+)'
|
||||
COMMIT_IGNORE_LINE = "--This line, and those below, will be ignored--"
|
||||
|
||||
###########################################################################
|
||||
# Subcommand Handler Return Values #
|
||||
@ -577,6 +578,15 @@ def relpath(path):
|
||||
return path[len(cwdprefix):]
|
||||
return path
|
||||
|
||||
def get_editor():
|
||||
if 'EDITOR' in os.environ and os.environ['EDITOR'] != '':
|
||||
return os.environ['EDITOR']
|
||||
for p_ent in os.environ['PATH'].split(':'):
|
||||
editor_path = os.path.join(p_ent, 'editor')
|
||||
if os.path.isfile(editor_path):
|
||||
return editor_path
|
||||
return 'vim'
|
||||
|
||||
###########################################################################
|
||||
# Subcommand Handlers #
|
||||
###########################################################################
|
||||
@ -1698,6 +1708,39 @@ def clean_h(argv, svn, out, config):
|
||||
os.unlink(cp)
|
||||
return RET_OK
|
||||
|
||||
def commit_h(argv, svn, out, config):
|
||||
argv = argv[1:] # strip command
|
||||
for arg in argv:
|
||||
if re.search(r'^-[Fm]', arg):
|
||||
# Do not handle the commit if the user supplied a -m or -F.
|
||||
return RET_REEXEC
|
||||
commit_file_fd, commit_file_fname = tempfile.mkstemp('.tmp', 'svn-commit')
|
||||
os.close(commit_file_fd)
|
||||
commit_file_fh = open(commit_file_fname, 'w')
|
||||
commit_file_fh.write("\n%s\n\n" % COMMIT_IGNORE_LINE)
|
||||
pout = Popen([svn, 'status'], stdout=PIPE).stdout
|
||||
commit_file_fh.write(pout.read())
|
||||
commit_file_fh.close()
|
||||
Popen([get_editor(), commit_file_fname]).wait()
|
||||
commit_file_fh = open(commit_file_fname, 'r')
|
||||
commit_file_contents = commit_file_fh.read()
|
||||
commit_file_fh.close()
|
||||
commit_message = ""
|
||||
for line in commit_file_contents.splitlines():
|
||||
if line == COMMIT_IGNORE_LINE:
|
||||
break
|
||||
commit_message += line + "\n"
|
||||
commit_message = commit_message.rstrip()
|
||||
if commit_message == "":
|
||||
out.write("Aborting commit due to empty commit message.")
|
||||
else:
|
||||
commit_file_fh = open(commit_file_fname, 'w')
|
||||
commit_file_fh.write(commit_message)
|
||||
commit_file_fh.close()
|
||||
Popen([svn, 'commit'] + argv + ['-F', commit_file_fname]).wait()
|
||||
os.unlink(commit_file_fname)
|
||||
return RET_OK
|
||||
|
||||
###########################################################################
|
||||
# Main #
|
||||
###########################################################################
|
||||
@ -1796,6 +1839,7 @@ def do_cmd(argv, realsvn, config, expand=True):
|
||||
'branch': branch_h,
|
||||
'checkout': checkout_h,
|
||||
'clean': clean_h,
|
||||
'commit': commit_h,
|
||||
'externals': externals_h,
|
||||
'switch': switch_h,
|
||||
'merge': merge_h,
|
||||
|
Loading…
x
Reference in New Issue
Block a user