- from_patchdir = os.path.join(git.base_dir, 'patches', from_name)
- if os.path.isdir(from_patchdir):
- os.rename(from_patchdir, to_patchdir)
- from_base = os.path.join(git.base_dir, 'refs', 'bases', from_name)
- if os.path.isfile(from_base):
- os.rename(from_base, to_base)
+ tree_id = None
+ if len(args) >= 2:
+ try:
+ if git.rev_parse(args[1]) == git.rev_parse('refs/heads/' + args[1]):
+ # we are for sure referring to a branch
+ parentbranch = 'refs/heads/' + args[1]
+ out.info('Recording "%s" as parent branch' % parentbranch)
+ elif git.rev_parse(args[1]) and re.search('/', args[1]):
+ # FIXME: should the test be more strict ?
+ parentbranch = args[1]
+ else:
+ # Note: this includes refs to StGIT patches
+ out.info('Don\'t know how to determine parent branch'
+ ' from "%s"' % args[1])
+ parentbranch = None
+ except git.GitException:
+ # should use a more specific exception to catch only
+ # non-git refs ?
+ out.info('Don\'t know how to determine parent branch'
+ ' from "%s"' % args[1])
+ parentbranch = None
+
+ tree_id = git_id(args[1])
+ else:
+ # branch stack off current branch
+ parentbranch = git.get_head_file()
+
+ if parentbranch:
+ parentremote = git.identify_remote(parentbranch)
+ if parentremote:
+ out.info('Using remote "%s" to pull parent from'
+ % parentremote)
+ else:
+ out.info('Recording as a local branch')
+ else:
+ # no known parent branch, can't guess the remote
+ parentremote = None