Survive capital punishment
cover Survive capital punishment
This series allows StGit to deal with a detached HEAD: in most cases it will just exit with a nice error message, but in some cases it will actually handle it.
Preceded by some more or less related cleanups. (The "explicit crt_series" patch was needed so that I could grep for the files that didn't contain crt_series.)
---
Karl Hasselström (6):
Let some commands work with detached HEAD Don't have a global crt_series in stgit.commans.common Refactor crt_series creation
Properly detect that HEAD is detached
Use our nice message printout wrapping system Allow caller to customize title of error/warning message
stgit/commands/add.py | 2 +- stgit/commands/branch.py | 8 ++++---- stgit/commands/clean.py | 4 ++-- stgit/commands/clone.py | 2 +- stgit/commands/commit.py | 2 +- stgit/commands/common.py | 24 ++++++++++++------------ stgit/commands/delete.py | 4 ++-- stgit/commands/diff.py | 9 +++++---- stgit/commands/edit.py | 6 +++--- stgit/commands/files.py | 4 ++-- stgit/commands/float.py | 6 +++--- stgit/commands/fold.py | 5 +++-- stgit/commands/goto.py | 8 ++++---- stgit/commands/id.py | 2 +- stgit/commands/imprt.py | 7 ++++--- stgit/commands/mail.py | 16 +++++++++------- stgit/commands/new.py | 2 +- stgit/commands/pick.py | 12 ++++++------ stgit/commands/pop.py | 8 ++++---- stgit/commands/pull.py | 14 +++++++------- stgit/commands/push.py | 8 ++++---- stgit/commands/rebase.py | 12 ++++++------ stgit/commands/refresh.py | 10 +++++----- stgit/commands/resolved.py | 2 +- stgit/commands/series.py | 5 +++-- stgit/commands/show.py | 2 +- stgit/commands/sink.py | 6 +++--- stgit/commands/status.py | 2 +- stgit/commands/sync.py | 8 ++++---- stgit/commands/uncommit.py | 2 +- stgit/git.py | 23 +++++++++++++++++------ stgit/main.py | 8 +++----- stgit/out.py | 12 ++++++------ 33 files changed, 130 insertions(+), 115 deletions(-)
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH 1/6 Allow caller to customize title of error/warning message
---
stgit/out.py | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
stgit/out.py +6 -6
@@ -85,12 +85,12 @@ class MessagePrinter(object): def info(self, *msgs): for msg in msgs: self.__out.single_line(msg) - def note(self, *msgs): - self.__out.tagged_lines('Notice', msgs) - def warn(self, *msgs): - self.__err.tagged_lines('Warning', msgs) - def error(self, *msgs): - self.__err.tagged_lines('Error', msgs) + def note(self, *msgs, **kw): + self.__out.tagged_lines(kw.get('title', 'Notice'), msgs) + def warn(self, *msgs, **kw): + self.__err.tagged_lines(kw.get('title', 'Warning'), msgs) + def error(self, *msgs, **kw): + self.__err.tagged_lines(kw.get('title', 'Error'), msgs) def start(self, msg): """Start a long-running operation.""" self.__out.single_line('%s ... ' % msg, print_newline = False)
PATCH 2/6 Use our nice message printout wrapping system
In reply to Karl Hasselström---
stgit/main.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
stgit/main.py +1 -1
@@ -282,7 +282,7 @@ def main(): command.func(parser, options, args) except (StgException, IOError, ParsingError, NoSectionError), err: - print >> sys.stderr, '%s %s: %s' % (prog, cmd, err) + out.error(str(err), title = '%s %s' % (prog, cmd)) if debug_level > 0: raise else:
PATCH 3/6 Properly detect that HEAD is detached
In reply to Karl HasselströmWe still error out on a lot of places we shouldn't, e.g. "stg branch" when on a detached HEAD, but at least now we give a sane error message.
---
stgit/git.py | 23 +++++++++++++++++------ 1 files changed, 17 insertions(+), 6 deletions(-)
stgit/git.py +17 -6
@@ -246,11 +246,19 @@ def get_head(): __head = rev_parse('HEAD') return __head +class DetachedHeadException(GitException): + def __init__(self): + GitException.__init__(self, 'Not on any branch') + def get_head_file(): - """Returns the name of the file pointed to by the HEAD link - """ - return strip_prefix('refs/heads/', - GRun('git-symbolic-ref', 'HEAD').output_one_line()) + """Return the name of the file pointed to by the HEAD symref. + Throw an exception if HEAD is detached.""" + try: + return strip_prefix( + 'refs/heads/', GRun('git-symbolic-ref', '-q', 'HEAD' + ).output_one_line()) + except GitRunException: + raise DetachedHeadException() def set_head_file(ref): """Resets HEAD to point to a new ref
@@ -385,8 +393,11 @@ def rename_ref(from_ref, to_ref): def rename_branch(from_name, to_name): """Rename a git branch.""" rename_ref('refs/heads/%s' % from_name, 'refs/heads/%s' % to_name) - if get_head_file() == from_name: - set_head_file(to_name) + try: + if get_head_file() == from_name: + set_head_file(to_name) + except DetachedHeadException: + pass # detached HEAD, so the renamee can't be the current branch reflog_dir = os.path.join(basedir.get(), 'logs', 'refs', 'heads') if os.path.exists(reflog_dir) \ and os.path.exists(os.path.join(reflog_dir, from_name)):
PATCH 4/6 Refactor crt_series creation
In reply to Karl HasselströmInstead of hard-coding in main.py which commands do and don't need a current series, let them speak for themselves.
---
stgit/commands/clone.py | 2 +- stgit/commands/common.py | 2 ++ stgit/main.py | 5 ++--- 3 files changed, 5 insertions(+), 4 deletions(-)
stgit/commands/clone.py +1 -1
@@ -29,7 +29,7 @@ usage = """%prog [options] <repository> <dir> Clone a GIT <repository> into the local <dir> and initialise the patch stack.""" -directory = DirectoryAnywhere() +directory = DirectoryAnywhere(needs_current_series = False) options = []
stgit/commands/common.py +2 -0
@@ -497,6 +497,8 @@ class DirectoryException(StgException): pass class _Directory(object): + def __init__(self, needs_current_series = True): + self.needs_current_series = needs_current_series @readonly_constant_property def git_dir(self): try:
stgit/main.py +2 -3
@@ -271,9 +271,8 @@ def main(): directory.setup() config_setup() - # 'clone' doesn't expect an already initialised GIT tree. A Series - # object will be created after the GIT tree is cloned - if cmd != 'clone': + # Some commands don't (always) need an initialized series. + if directory.needs_current_series: if hasattr(options, 'branch') and options.branch: command.crt_series = Series(options.branch) else:
PATCH 5/6 Don't have a global crt_series in stgit.commans.common
In reply to Karl HasselströmGlobal variables baaad. Instead, pass it as a parameter to the functions that need it.
---
stgit/commands/branch.py | 8 ++++---- stgit/commands/clean.py | 4 ++-- stgit/commands/commit.py | 2 +- stgit/commands/common.py | 22 ++++++++++------------ stgit/commands/delete.py | 4 ++-- stgit/commands/diff.py | 7 ++++--- stgit/commands/edit.py | 6 +++--- stgit/commands/files.py | 4 ++-- stgit/commands/float.py | 6 +++--- stgit/commands/fold.py | 5 +++-- stgit/commands/goto.py | 8 ++++---- stgit/commands/id.py | 2 +- stgit/commands/imprt.py | 7 ++++--- stgit/commands/mail.py | 16 +++++++++------- stgit/commands/new.py | 2 +- stgit/commands/pick.py | 12 ++++++------ stgit/commands/pop.py | 8 ++++---- stgit/commands/pull.py | 14 +++++++------- stgit/commands/push.py | 8 ++++---- stgit/commands/rebase.py | 12 ++++++------ stgit/commands/refresh.py | 10 +++++----- stgit/commands/series.py | 5 +++-- stgit/commands/show.py | 2 +- stgit/commands/sink.py | 6 +++--- stgit/commands/sync.py | 8 ++++---- stgit/commands/uncommit.py | 2 +- stgit/main.py | 1 - 27 files changed, 97 insertions(+), 94 deletions(-)
stgit/commands/branch.py +4 -4
@@ -112,7 +112,7 @@ def func(parser, options, args): check_local_changes() check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) tree_id = None if len(args) >= 2:
@@ -141,7 +141,7 @@ def func(parser, options, args): # exception in branch = rev_parse() leaves branchpoint unbound branchpoint = None - tree_id = branchpoint or git_id(args[1]) + tree_id = branchpoint or git_id(crt_series, args[1]) if parentbranch: out.info('Recording "%s" as parent branch' % parentbranch)
@@ -182,7 +182,7 @@ def func(parser, options, args): check_local_changes() check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) out.start('Cloning current branch to "%s"' % clone) crt_series.clone(clone)
@@ -294,7 +294,7 @@ def func(parser, options, args): check_local_changes() check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) out.start('Switching to branch "%s"' % args[0]) git.switch_branch(args[0])
stgit/commands/clean.py +2 -2
@@ -61,7 +61,7 @@ def func(parser, options, args): check_local_changes() check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) if not (options.applied or options.unapplied): options.applied = options.unapplied = True
@@ -74,4 +74,4 @@ def func(parser, options, args): unapplied = crt_series.get_unapplied() __delete_empty(unapplied, False) - print_crt_patch() + print_crt_patch(crt_series)
stgit/commands/commit.py +1 -1
@@ -45,7 +45,7 @@ def func(parser, options, args): check_local_changes() check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) applied = crt_series.get_applied() if not applied:
stgit/commands/common.py +10 -12
@@ -28,8 +28,6 @@ from stgit.run import * from stgit import stack, git, basedir from stgit.config import config, file_extensions -crt_series = None - # Command exception class class CmdException(StgException):
@@ -74,7 +72,7 @@ def parse_rev(rev): # No, we can't parse that. raise RevParseException -def git_id(rev): +def git_id(crt_series, rev): """Return the GIT id """ if not rev:
@@ -112,7 +110,7 @@ def check_local_changes(): raise CmdException, \ 'local changes in the tree. Use "refresh" or "status --reset"' -def check_head_top_equal(): +def check_head_top_equal(crt_series): if not crt_series.head_top_equal(): raise CmdException( """HEAD and top are not the same. This can happen if you
@@ -125,7 +123,7 @@ def check_conflicts(): 'Unsolved conflicts. Please resolve them first or\n' \ ' revert the changes with "status --reset"' -def print_crt_patch(branch = None): +def print_crt_patch(crt_series, branch = None): if not branch: patch = crt_series.get_current() else:
@@ -158,7 +156,7 @@ def resolved_all(reset = None): resolved(filename, reset) os.remove(os.path.join(basedir.get(), 'conflicts')) -def push_patches(patches, check_merged = False): +def push_patches(crt_series, patches, check_merged = False): """Push multiple patches onto the stack. This function is shared between the push and pull commands """
@@ -197,7 +195,7 @@ def push_patches(patches, check_merged = False): else: out.done() -def pop_patches(patches, keep = False): +def pop_patches(crt_series, patches, keep = False): """Pop the patches in the list from the stack. It is assumed that the patches are listed in the stack reverse order. """
@@ -319,7 +317,7 @@ def address_or_alias(addr_str): for addr in addr_str.split(',')] return ', '.join([addr for addr in addr_list if addr]) -def prepare_rebase(): +def prepare_rebase(crt_series): # pop all patches applied = crt_series.get_applied() if len(applied) > 0:
@@ -328,9 +326,9 @@ def prepare_rebase(): out.done() return applied -def rebase(target): +def rebase(crt_series, target): try: - tree_id = git_id(target) + tree_id = git_id(crt_series, target) except: # it might be that we use a custom rebase command with its own # target type
@@ -345,12 +343,12 @@ def rebase(target): git.rebase(tree_id = tree_id) out.done() -def post_rebase(applied, nopush, merged): +def post_rebase(crt_series, applied, nopush, merged): # memorize that we rebased to here crt_series._set_field('orig-base', git.get_head()) # push the patches back if not nopush: - push_patches(applied, merged) + push_patches(crt_series, applied, merged) # # Patch description/e-mail/diff parsing
stgit/commands/delete.py +2 -2
@@ -71,7 +71,7 @@ def func(parser, options, args): if applied and not options.branch: check_local_changes() check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) # delete the patches for patch in applied + patches:
@@ -79,4 +79,4 @@ def func(parser, options, args): out.info('Patch "%s" successfully deleted' % patch) if not options.branch: - print_crt_patch() + print_crt_patch(crt_series)
stgit/commands/diff.py +4 -3
@@ -86,9 +86,10 @@ def func(parser, options, args): diff_flags = [] if options.stat: - out.stdout_raw(git.diffstat(args, git_id(rev1), git_id(rev2)) + '\n') + out.stdout_raw(git.diffstat(args, git_id(crt_series, rev1), + git_id(crt_series, rev2)) + '\n') else: - diff_str = git.diff(args, git_id(rev1), git_id(rev2), - diff_flags = diff_flags ) + diff_str = git.diff(args, git_id(crt_series, rev1), + git_id(crt_series, rev2), diff_flags = diff_flags ) if diff_str: pager(diff_str)
stgit/commands/edit.py +3 -3
@@ -203,13 +203,13 @@ def func(parser, options, args): check_local_changes() check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) if pname != crt_pname: # Go to the patch to be edited applied = crt_series.get_applied() between = applied[:applied.index(pname):-1] - pop_patches(between) + pop_patches(crt_series, between) if options.author: options.authname, options.authemail = name_email(options.author)
@@ -241,4 +241,4 @@ def func(parser, options, args): if pname != crt_pname: # Push the patches back between.reverse() - push_patches(between) + push_patches(crt_series, between)
stgit/commands/files.py +2 -2
@@ -57,8 +57,8 @@ def func(parser, options, args): else: parser.error('incorrect number of arguments') - rev1 = git_id('%s//bottom' % patch) - rev2 = git_id('%s//top' % patch) + rev1 = git_id(crt_series, '%s//bottom' % patch) + rev2 = git_id(crt_series, '%s//top' % patch) if options.stat: out.stdout_raw(git.diffstat(rev1 = rev1, rev2 = rev2) + '\n')
stgit/commands/float.py +3 -3
@@ -46,7 +46,7 @@ def func(parser, options, args): check_local_changes() check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) unapplied = crt_series.get_unapplied() applied = crt_series.get_applied()
@@ -85,7 +85,7 @@ def func(parser, options, args): # check whether the operation is really needed if topop != topush: if topop: - pop_patches(topop) + pop_patches(crt_series, topop) if topush: topush.reverse() - push_patches(topush) + push_patches(crt_series, topush)
stgit/commands/fold.py +3 -2
@@ -50,7 +50,7 @@ def func(parser, options, args): check_local_changes() check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) if len(args) == 1: filename = args[0]
@@ -74,7 +74,8 @@ def func(parser, options, args): bottom = crt_patch.get_bottom() git.apply_patch(filename = filename, base = bottom) elif options.base: - git.apply_patch(filename = filename, base = git_id(options.base)) + git.apply_patch(filename = filename, + base = git_id(crt_series, options.base)) else: git.apply_patch(filename = filename)
stgit/commands/goto.py +4 -4
@@ -44,7 +44,7 @@ def func(parser, options, args): parser.error('incorrect number of arguments') check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) if not options.keep: check_local_changes()
@@ -56,13 +56,13 @@ def func(parser, options, args): if patch in applied: applied.reverse() patches = applied[:applied.index(patch)] - pop_patches(patches, options.keep) + pop_patches(crt_series, patches, options.keep) elif patch in unapplied: if options.keep: raise CmdException, 'Cannot use --keep with patch pushing' patches = unapplied[:unapplied.index(patch)+1] - push_patches(patches) + push_patches(crt_series, patches) else: raise CmdException, 'Patch "%s" does not exist' % patch - print_crt_patch() + print_crt_patch(crt_series)
stgit/commands/id.py +1 -1
@@ -48,4 +48,4 @@ def func(parser, options, args): else: parser.error('incorrect number of arguments') - out.stdout(git_id(id_str)) + out.stdout(git_id(crt_series, id_str))
stgit/commands/imprt.py +4 -3
@@ -165,7 +165,8 @@ def __create_patch(filename, message, author_name, author_email, else: out.start('Importing patch "%s"' % patch) if options.base: - git.apply_patch(diff = diff, base = git_id(options.base)) + git.apply_patch(diff = diff, + base = git_id(crt_series, options.base)) else: git.apply_patch(diff = diff) crt_series.refresh_patch(edit = options.edit,
@@ -270,7 +271,7 @@ def func(parser, options, args): check_local_changes() check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) if len(args) == 1: filename = args[0]
@@ -286,4 +287,4 @@ def func(parser, options, args): else: __import_file(filename, options) - print_crt_patch() + print_crt_patch(crt_series)
stgit/commands/mail.py +9 -7
@@ -350,8 +350,8 @@ def __build_cover(tmpl, patches, msg_id, options): 'shortlog': stack.shortlog(crt_series.get_patch(p) for p in patches), 'diffstat': git.diffstat( - rev1 = git_id('%s//bottom' % patches[0]), - rev2 = git_id('%s//top' % patches[-1]))} + rev1 = git_id(crt_series, '%s//bottom' % patches[0]), + rev2 = git_id(crt_series, '%s//top' % patches[-1]))} try: msg_string = tmpl % tmpl_dict
@@ -435,11 +435,13 @@ def __build_message(tmpl, patch, patch_nr, total_nr, msg_id, ref_id, options): 'longdescr': long_descr, # for backward template compatibility 'endofheaders': '', - 'diff': git.diff(rev1 = git_id('%s//bottom' % patch), - rev2 = git_id('%s//top' % patch), - diff_flags = diff_flags ), - 'diffstat': git.diffstat(rev1 = git_id('%s//bottom'%patch), - rev2 = git_id('%s//top' % patch)), + 'diff': git.diff( + rev1 = git_id(crt_series, '%s//bottom' % patch), + rev2 = git_id(crt_series, '%s//top' % patch), + diff_flags = diff_flags), + 'diffstat': git.diffstat( + rev1 = git_id(crt_series, '%s//bottom'%patch), + rev2 = git_id(crt_series, '%s//top' % patch)), # for backward template compatibility 'date': '', 'version': version_str,
stgit/commands/new.py +1 -1
@@ -70,7 +70,7 @@ def func(parser, options, args): parser.error('incorrect number of arguments') check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) if options.author: options.authname, options.authemail = name_email(options.author)
stgit/commands/pick.py +6 -6
@@ -65,10 +65,10 @@ def func(parser, options, args): if not options.unapplied: check_local_changes() check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) commit_str = args[0] - commit_id = git_id(commit_str) + commit_id = git_id(crt_series, commit_str) commit = git.Commit(commit_id) if options.fold or options.update:
@@ -84,7 +84,7 @@ def func(parser, options, args): patchname = None if options.parent: - parent = git_id(options.parent) + parent = git_id(crt_series, options.parent) else: parent = commit.get_parent()
@@ -104,8 +104,8 @@ def func(parser, options, args): out.done() elif options.update: - rev1 = git_id('//bottom') - rev2 = git_id('//top') + rev1 = git_id(crt_series, '//bottom') + rev2 = git_id(crt_series, '//top') files = git.barefiles(rev1, rev2).split('\n') out.start('Updating with commit %s' % commit_id)
@@ -163,4 +163,4 @@ def func(parser, options, args): else: out.done() - print_crt_patch() + print_crt_patch(crt_series)
stgit/commands/pop.py +4 -4
@@ -51,7 +51,7 @@ def func(parser, options, args): """Pop the topmost patch from the stack """ check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) if not options.keep: check_local_changes()
@@ -83,8 +83,8 @@ def func(parser, options, args): raise CmdException, 'Cannot pop arbitrary patches with --keep' topop.reverse() - pop_patches(topop, options.keep) + pop_patches(crt_series, topop, options.keep) if topush: - push_patches(topush) + push_patches(crt_series, topush) - print_crt_patch() + print_crt_patch(crt_series)
stgit/commands/pull.py +7 -7
@@ -74,12 +74,12 @@ def func(parser, options, args): check_local_changes() check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) if policy not in ['pull', 'fetch-rebase', 'rebase']: raise GitConfigException, 'Unsupported pull-policy "%s"' % policy - applied = prepare_rebase() + applied = prepare_rebase(crt_series) # pull the remote changes if policy == 'pull':
@@ -92,17 +92,17 @@ def func(parser, options, args): target = git.fetch_head() except git.GitException: out.error('Could not find the remote head to rebase onto, pushing any patches back...') - post_rebase(applied, False, False) + post_rebase(crt_series, applied, False, False) raise CmdException, 'Could not find the remote head to rebase onto - fix branch.%s.merge in .git/config' % crt_series.get_name() - rebase(target) + rebase(crt_series, target) elif policy == 'rebase': - rebase(crt_series.get_parent_branch()) + rebase(crt_series, crt_series.get_parent_branch()) - post_rebase(applied, options.nopush, options.merged) + post_rebase(crt_series, applied, options.nopush, options.merged) # maybe tidy up if config.get('stgit.keepoptimized') == 'yes': git.repack() - print_crt_patch() + print_crt_patch(crt_series)
stgit/commands/push.py +4 -4
@@ -72,13 +72,13 @@ def func(parser, options, args): out.done() else: out.done('patch unchanged') - print_crt_patch() + print_crt_patch(crt_series) return check_local_changes() check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) unapplied = crt_series.get_unapplied() if not unapplied:
@@ -99,6 +99,6 @@ def func(parser, options, args): if options.reverse: patches.reverse() - push_patches(patches, options.merged) + push_patches(crt_series, patches, options.merged) - print_crt_patch() + print_crt_patch(crt_series)
stgit/commands/rebase.py +6 -6
@@ -48,14 +48,14 @@ def func(parser, options, args): check_local_changes() check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) # ensure an exception is raised before popping on non-existent target - if git_id(args[0]) == None: + if git_id(crt_series, args[0]) == None: raise GitException, 'Unknown revision: %s' % args[0] - applied = prepare_rebase() - rebase(args[0]) - post_rebase(applied, options.nopush, options.merged) + applied = prepare_rebase(crt_series) + rebase(crt_series, args[0]) + post_rebase(crt_series, applied, options.nopush, options.merged) - print_crt_patch() + print_crt_patch(crt_series)
stgit/commands/refresh.py +5 -5
@@ -73,7 +73,7 @@ def func(parser, options, args): raise CmdException, 'No patches applied' if not options.force: - check_head_top_equal() + check_head_top_equal(crt_series) if options.undo: out.start('Undoing the refresh of "%s"' % patch)
@@ -89,10 +89,10 @@ def func(parser, options, args): if options.patch: applied = crt_series.get_applied() between = applied[:applied.index(patch):-1] - pop_patches(between, keep = True) + pop_patches(crt_series, between, keep = True) elif options.update: - rev1 = git_id('//bottom') - rev2 = git_id('//top') + rev1 = git_id(crt_series, '//bottom') + rev2 = git_id(crt_series, '//top') patch_files = git.barefiles(rev1, rev2).split('\n') files = [f for f in files if f in patch_files] if not files:
@@ -113,7 +113,7 @@ def func(parser, options, args): if options.patch: between.reverse() - push_patches(between) + push_patches(crt_series, between) elif options.annotate: # only annotate the top log entry as there is no need to # refresh the patch and generate a full commit
stgit/commands/series.py +3 -2
@@ -195,12 +195,13 @@ def func(parser, options, args): raise CmdException, '--graphical not supported with --missing' if applied: - gitk_args = ' %s^..%s' % (git_id(applied[0]), git_id(applied[-1])) + gitk_args = ' %s^..%s' % (git_id(crt_series, applied[0]), + git_id(crt_series, applied[-1])) else: gitk_args = '' for p in unapplied: - patch_id = git_id(p) + patch_id = git_id(crt_series, p) gitk_args += ' %s^..%s' % (patch_id, patch_id) if os.system('gitk%s' % gitk_args) != 0:
stgit/commands/show.py +1 -1
@@ -69,7 +69,7 @@ def func(parser, options, args): else: diff_flags = [] - commit_ids = [git_id(patch) for patch in patches] + commit_ids = [git_id(crt_series, patch) for patch in patches] commit_str = '\n'.join([git.pretty_commit(commit_id, diff_flags=diff_flags) for commit_id in commit_ids]) if commit_str:
stgit/commands/sink.py +3 -3
@@ -45,7 +45,7 @@ def func(parser, options, args): check_local_changes() check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) oldapplied = crt_series.get_applied() unapplied = crt_series.get_unapplied()
@@ -61,10 +61,10 @@ def func(parser, options, args): patches = [ crt_series.get_current() ] crt_series.pop_patch(options.to or oldapplied[0]) - push_patches(patches) + push_patches(crt_series, patches) if not options.nopush: newapplied = crt_series.get_applied() def not_reapplied_yet(p): return not p in newapplied - push_patches(filter(not_reapplied_yet, oldapplied)) + push_patches(crt_series, filter(not_reapplied_yet, oldapplied))
stgit/commands/sync.py +4 -4
@@ -51,7 +51,7 @@ options = [make_option('-a', '--all', def __check_all(): check_local_changes() check_conflicts() - check_head_top_equal() + check_head_top_equal(crt_series) def __branch_merge_patch(remote_series, pname): """Merge a patch from a remote branch into the current tree.
@@ -131,13 +131,13 @@ def func(parser, options, args): # pop to the one before the first patch to be synchronised popped = applied[applied.index(sync_patches[0]) + 1:] if popped: - pop_patches(popped[::-1]) + pop_patches(crt_series, popped[::-1]) for p in sync_patches: if p in popped: # push to this patch idx = popped.index(p) + 1 - push_patches(popped[:idx]) + push_patches(crt_series, popped[:idx]) del popped[:idx] # the actual sync
@@ -166,4 +166,4 @@ def func(parser, options, args): # push the remaining patches if popped: - push_patches(popped) + push_patches(crt_series, popped)
stgit/commands/uncommit.py +1 -1
@@ -66,7 +66,7 @@ def func(parser, options, args): if len(args) != 0: parser.error('cannot specify patch name with --to') patch_nr = patchnames = None - to_commit = git_id(options.to) + to_commit = git_id(crt_series, options.to) elif options.number: if options.number <= 0: parser.error('invalid value passed to --number')
stgit/main.py +0 -1
@@ -277,7 +277,6 @@ def main(): command.crt_series = Series(options.branch) else: command.crt_series = Series() - stgit.commands.common.crt_series = command.crt_series command.func(parser, options, args) except (StgException, IOError, ParsingError, NoSectionError), err:
PATCH 6/6 Let some commands work with detached HEAD
In reply to Karl Hasselströmadd, diff, resolved, and status didn't use the crt_series that was initialized for them. So don't initialize it, since that means (1) less work and (2) they won't fail when HEAD is detached.
Note that this doesn't completely fix the problem with detached HEAD:
a number of other commands (e.g. branch) don't always need to refer to a current series, but currently fails on a detached HEAD even in those situations.
---
stgit/commands/add.py | 2 +- stgit/commands/diff.py | 2 +- stgit/commands/resolved.py | 2 +- stgit/commands/status.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
stgit/commands/add.py +1 -1
@@ -31,7 +31,7 @@ Add the files or directories passed as arguments to the repository. When a directory name is given, all the files and subdirectories are recursively added.""" -directory = DirectoryHasRepository() +directory = DirectoryHasRepository(needs_current_series = False) options = []
stgit/commands/diff.py +1 -1
@@ -42,7 +42,7 @@ rev = '([patch][//[bottom | top]]) | <tree-ish> | base' If neither bottom nor top are given but a '//' is present, the command shows the specified patch (defaulting to the current one).""" -directory = DirectoryHasRepository() +directory = DirectoryHasRepository(needs_current_series = False) options = [make_option('-r', '--range', metavar = 'rev1[..[rev2]]', dest = 'revs', help = 'show the diff between revisions'),
stgit/commands/resolved.py +1 -1
@@ -34,7 +34,7 @@ Mark a merge conflict as resolved. The conflicts can be seen with the 'C'. This command also removes any <file>.{ancestor,current,patched} files.""" -directory = DirectoryHasRepository() +directory = DirectoryHasRepository(needs_current_series = False) options = [make_option('-a', '--all', help = 'mark all conflicts as solved', action = 'store_true'),
stgit/commands/status.py +1 -1
@@ -40,7 +40,7 @@ under revision control. The files are prefixed as follows: A 'refresh' command clears the status of the modified, new and deleted files.""" -directory = DirectoryHasRepository() +directory = DirectoryHasRepository(needs_current_series = False) options = [make_option('-m', '--modified', help = 'show modified files only', action = 'store_true'),
Re: [StGit PATCH 6/6] Let some commands work with detached HEAD
stgit/commands/diff.py rev = '([patch][//[bottom | top]]) | <tree-ish> | base' · line 48
Quoted 11 lines · Karl Hasselström
stgit/commands/diff.py +1
-1@@ -42,7 +42,7 @@ rev = '([patch][//[bottom | top]]) | <tree-ish> | base' If neither bottom nor top are given but a '//' is present, the command shows the specified patch (defaulting to the current one).""" -directory = DirectoryHasRepository() +directory = DirectoryHasRepository(needs_current_series = False) options = [make_option('-r', '--range', metavar = 'rev1[..[rev2]]', dest = 'revs', help = 'show the diff between revisions'),
This hunk shouldn't be here, since diff does use crt_series. (The commit message also has to be modified accordingly.)
So, we don't have a single test that tries to run "stg diff". Duh.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH 1/1 New test: "stg diff"
A simple test to make sure that we can run "stg diff" without arguments, just to list local changes.
Note that two subtests currently fail; these are due to plain "stg diff" failing on a branch where "stg init" hasn't been run, which is plainly a bug.
---
Quoted 1 line · Karl Hasselström
So, we don't have a single test that tries to run "stg diff". Duh.
t/t2400-diff.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 files changed, 37 insertions(+), 0 deletions(-) create mode 100755 t/t2400-diff.sh
t/t2400-diff.sh new file +37 -0
@@ -0,0 +1,37 @@ +#!/bin/sh + +test_description='Run "stg diff"' + +. ./test-lib.sh + +test_expect_failure 'Diff with no StGit data' ' + stg diff +' + +test_expect_success 'Make some local changes' ' + echo foo >> foo.txt && + git add foo.txt +' + +test_expect_failure 'Diff with some local changes' ' + stg diff +' + +test_expect_success 'Initialize StGit stuff' ' + stg init && + stg new foo -m foo +' + +test_expect_success 'Diff with some local changes' ' + stg diff +' + +test_expect_success 'Refresh patch' ' + stg refresh +' + +test_expect_success 'Diff with no local changes' ' + stg diff +' + +test_done
Re: [StGit PATCH 6/6] Let some commands work with detached HEAD
In reply to Karl HasselströmQuoted 2 lines · Karl Hasselström
This hunk shouldn't be here, since diff does use
crt_series. (The commit message also has to be modified accordingly.)
I've fixed the patch and pushed it out, along with the two new ones. For good measure, I also demoted it from safe to experimental.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Quoted 7 lines · Karl Hasselström
Karl Hasselström (6):
Let some commands work with detached HEAD Don't have a globalcrt_seriesin stgit.commans.common Refactorcrt_seriescreation
Properly detect that HEAD is detached
Use our nice message printout wrapping system Allow caller to customize title of error/warning message
Will be available from
git://repo.or.cz/stgit/kha.git safe
momentarily (I just need to rebase the experimental branch on top of it).
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Quoted 6 lines · Karl Hasselström
Will be available from
git://repo.or.cz/stgit/kha.gitsafemomentarily (I just need to rebase the experimental branch on top of it).
There; both safe and experimental are updated. (It takes a while to rebase when you run the test suite for every patch ...)
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle