Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RF: AnnexRepo.get_corresponding_branch() -> None without a managed branch #4274

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions datalad/distribution/tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,7 @@ def check_merge_follow_parentds_subdataset_detached(on_adjusted, path):
# the explicit revision fetch fails.
(ds_src_s1.pathobj / "bar").write_text("bar content")
ds_src.save(recursive=True)
ds_src_s1.repo.checkout(
ds_src_s1.repo.get_corresponding_branch("master"))
ds_src_s1.repo.checkout('master')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, that was silly of me. I guess in some earlier iteration that was a plain .get_corresponding_branch(), and I didn't drop the call when I switched to explicitly using "master", or something :x

# This is the default, but just in case:
ds_src_s1.repo.config.set("uploadpack.allowAnySHA1InWant", "false",
where="local")
Expand Down
38 changes: 16 additions & 22 deletions datalad/support/annexrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,25 +465,19 @@ def is_managed_branch(self, branch=None):
return False

def get_corresponding_branch(self, branch=None):
"""In case of a managed branch, get the corresponding one.

If `branch` is not a managed branch, return that branch without any
changes.

Note: Since default for `branch` is the active branch,
`get_corresponding_branch()` is equivalent to `get_active_branch()` if
the active branch is not a managed branch.
"""Get the name of a potential corresponding branch.

Parameters
----------
branch: str
name of the branch; defaults to active branch
branch: str, optional
Name of the branch to report a corresponding branch for;
defaults to active branch

Returns
-------
str
name of the corresponding branch if there is any, name of the queried
branch otherwise.
str or None
Name of the corresponding branch, or `None` if there is no
corresponding branch.
"""

if branch is None:
Expand All @@ -509,7 +503,7 @@ def get_corresponding_branch(self, branch=None):
return cor_branch

else:
return branch
return None

def get_tracking_branch(self, branch=None, remote_only=False,
corresponding=True):
Expand Down Expand Up @@ -539,9 +533,9 @@ def get_tracking_branch(self, branch=None, remote_only=False,
branch = self.get_active_branch()

return super(AnnexRepo, self).get_tracking_branch(
remote_only=remote_only,
branch=self.get_corresponding_branch(branch)
if corresponding else branch)
remote_only=remote_only,
branch=(self.get_corresponding_branch(branch) or branch)
if corresponding else branch)

@classmethod
def _check_git_annex_version(cls):
Expand Down Expand Up @@ -1241,7 +1235,8 @@ def _init(self, version=None, description=None):
self.config.sections()]
for sct in sections_to_preserve:
orig_branch = sct[7:]
new_branch = self.get_corresponding_branch(orig_branch)
new_branch = \
self.get_corresponding_branch(orig_branch) or orig_branch
new_section = "branch.{}".format(new_branch)
for opt in self.config.options(sct):
orig_value = self.config.get_value(sct, opt)
Expand Down Expand Up @@ -3494,17 +3489,16 @@ def localsync(self, remote=None, managed_only=False):
"""
branch = self.get_active_branch()
corresponding_branch = self.get_corresponding_branch(branch)
branch = corresponding_branch or branch

have_corresponding_branch = branch != corresponding_branch

if managed_only and not have_corresponding_branch:
if managed_only and not corresponding_branch:
lgr.debug('No sync necessary, no corresponding branch detected')
return

lgr.debug(
"Sync local 'git-annex' branch%s.",
", and corresponding '{}' branch".format(corresponding_branch)
if have_corresponding_branch else '')
if corresponding_branch else '')

synced_branch = 'synced/{}'.format(corresponding_branch)
had_synced_branch = synced_branch in self.get_branches()
Expand Down
4 changes: 4 additions & 0 deletions datalad/support/gitrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1914,6 +1914,10 @@ def get_active_branch(self):
raise e
return out.strip()[11:] # strip refs/heads/

def get_corresponding_branch(self, branch=None):
"""Always returns None, a plain GitRepo has no managed branches"""
return None

def get_branches(self):
"""Get all branches of the repo.

Expand Down
2 changes: 1 addition & 1 deletion datalad/support/tests/test_annexrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,7 @@ def test_AnnexRepo_get_corresponding_branch(path):
ar = AnnexRepo(path)

# we should be on master.
eq_('master', ar.get_corresponding_branch())
eq_('master', ar.get_corresponding_branch() or ar.get_active_branch())

# special case v6 adjusted branch is not provided by a dedicated build:
if ar.supports_unlocked_pointers:
Expand Down