Show rebase help during interactive import

This commit extends the todo epilogue to include the usage text that is
shown during a standard git rebase.

The specific content of this can vary between Git versions, though only
slightly. The main change I can see looking at
https://github.com/git/git/blame/master/git-rebase--interactive.sh is
that a "drop" command was added 2.6.0 onwards, so two epilogue files are
supplied to deal with this. Further ones could be added in the future.

Change-Id: I89a840c6a02960c9f0f0204d85a3dd162e0a759a
This commit is contained in:
Paul Bourke 2016-05-26 13:05:44 +01:00
parent e52e277dd7
commit 00377869a9
5 changed files with 56 additions and 13 deletions

View File

@ -15,6 +15,7 @@
# limitations under the License.
#
import os
import pkg_resources
@ -32,3 +33,5 @@ except pkg_resources.DistributionNotFound:
_version_info = pbr.version.VersionInfo('git-upstream')
__version__ = _version_info.release_string()
__canonical_version__ = _version_info.version_string()
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

View File

@ -16,11 +16,13 @@
#
import codecs
import git
import os
import subprocess
from git_upstream.lib.utils import GitMixin
from git_upstream.log import LogDedentMixin
from git_upstream import PROJECT_ROOT
REBASE_EDITOR_SCRIPT = "rebase-editor"
@ -28,17 +30,6 @@ REBASE_EDITOR_SCRIPT = "rebase-editor"
# enable syntax highlighting
REBASE_EDITOR_TODO = "git-upstream/git-rebase-todo"
TODO_EPILOGUE = """
# Rebase %(shortrevisions)s onto %(shortonto)s
#
# All commands from normal rebase instructions files are supported
#
# If you remove a line, that commit will be dropped.
# Removing all commits will abort the rebase.
#
"""
class RebaseEditor(GitMixin, LogDedentMixin):
@ -61,6 +52,15 @@ class RebaseEditor(GitMixin, LogDedentMixin):
def editor(self):
return self._editor
def _todo_epilogue(self):
if git.Git().version_info < (2, 6, 0):
resource = 'todo_epilogue_1_7_5.txt'
else:
resource = 'todo_epilogue_2_6_0.txt'
with open('%s/resources/%s' % (PROJECT_ROOT, resource),
'r') as epilogue:
return epilogue.read()
def _write_todo(self, commits, *args, **kwargs):
todo_file = os.path.join(self.repo.git_dir, REBASE_EDITOR_TODO)
if os.path.exists(todo_file):
@ -90,7 +90,7 @@ class RebaseEditor(GitMixin, LogDedentMixin):
if not root:
todo.write("noop\n")
todo.write(TODO_EPILOGUE %
todo.write(self._todo_epilogue() %
{'shortrevisions': "%s..%s" % (self._shorten(root),
self._shorten(commit)),
'shortonto': self._shorten(onto or root)})

View File

@ -0,0 +1,18 @@
# Rebase %(shortrevisions)s onto %(shortonto)s
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

View File

@ -0,0 +1,19 @@
# Rebase %(shortrevisions)s onto %(shortonto)s
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

View File

@ -28,8 +28,11 @@ skip_changelog = True
[files]
packages =
git_upstream
data_files =
data_files =
etc/bash_completion.d = bash_completion/git-upstream
extra_files =
git_upstream/resources/todo_epilogue_2_6_0.txt
git_upstream/resources/todo_epilogue_1_7_5.txt
[entry_points]
console_scripts =