464
467
# Git doesn't do stacking (yet...)
465
468
raise branch.UnstackableBranchFormat(self._format, self.base)
470
def _get_push_origin(self, cs):
471
"""Get the name for the push origin.
473
The exact behaviour is documented in the git-config(1) manpage.
476
return cs.get((b'branch', self.name.encode('utf-8')), b'pushRemote')
479
return cs.get((b'branch', ), b'remote')
482
return cs.get((b'branch', self.name.encode('utf-8')), b'remote')
486
def _get_origin(self, cs):
488
return cs.get((b'branch', self.name.encode('utf-8')), b'remote')
492
def _get_related_push_branch(self, cs):
493
remote = self._get_push_origin(cs)
495
location = cs.get((b"remote", remote), b"url")
499
return git_url_to_bzr_url(location.decode('utf-8'), ref=self.ref)
501
def _get_related_merge_branch(self, cs):
502
remote = self._get_origin(cs)
504
location = cs.get((b"remote", remote), b"url")
509
ref = cs.get((b"branch", remote), b"merge")
513
return git_url_to_bzr_url(location.decode('utf-8'), ref=ref)
467
515
def _get_parent_location(self):
468
516
"""See Branch.get_parent()."""
469
# FIXME: Set "origin" url from .git/config ?
470
517
cs = self.repository._git.get_config_stack()
472
location = cs.get((b"remote", b'origin'), b"url")
478
ref = cs.get((b"remote", b"origin"), b"merge")
484
params['branch'] = urlutils.escape(ref_to_branch_name(ref))
486
params['ref'] = urlutils.quote_from_bytes(ref)
488
url = git_url_to_bzr_url(location.decode('utf-8'))
489
return urlutils.join_segment_parameters(url, params)
518
return self._get_related_merge_branch(cs)
520
def _write_git_config(self, cs):
523
self.repository._git._put_named_file('config', f.getvalue())
491
525
def set_parent(self, location):
492
# FIXME: Set "origin" url in .git/config ?
493
526
cs = self.repository._git.get_config()
527
remote = self._get_origin(cs)
494
528
this_url = urlutils.split_segment_parameters(self.user_url)[0]
495
target_url, target_params = urlutils.split_segment_parameters(location)
529
target_url, branch, ref = bzr_url_to_git_url(location)
496
530
location = urlutils.relative_url(this_url, target_url)
497
cs.set((b"remote", b"origin"), b"url", location)
498
if 'branch' in target_params:
499
cs.set((b"remote", b"origin"), b"merge",
500
branch_name_to_ref(target_params['branch']))
501
elif 'ref' in target_params:
502
cs.set((b"remote", b"origin"), b"merge",
503
target_params['ref'])
531
cs.set((b"remote", remote), b"url", location)
533
cs.set((b"branch", remote), b"merge", branch_name_to_ref(branch))
535
cs.set((b"branch", remote), b"merge", ref)
505
537
# TODO(jelmer): Maybe unset rather than setting to HEAD?
506
cs.set((b"remote", b"origin"), b"merge", 'HEAD')
509
self.repository._git._put_named_file('config', f.getvalue())
538
cs.set((b"branch", remote), b"merge", b'HEAD')
539
self._write_git_config(cs)
511
541
def break_lock(self):
512
542
raise NotImplementedError(self.break_lock)