Skip to content

Commit

Permalink
filter-repo: handle origin refs without origin remote
Browse files Browse the repository at this point in the history
git-svn creates references of the form refs/remotes/origin/..., even
though it does not actually set up an origin remote.  Prior to
  a12d742 (filter-repo: notify users when we remove the origin
                remote, 2024-07-30)
this would have resulted in a
  fatal: No such remote: 'origin'
error from the attempt to run `git remote rm origin`.  However, the exit
status of the command was ignored so filter-repo would have continued on
and ended up getting the right result, just scaring users.  Still
suboptimal, but at least it worked.  Since the above-mentioned commit,
though, the code would die with a traceback stating that
b'remote.origin.url' was not found in self._config_settings.

Just return early from _migrate_origin_to_heads() when there is no
remote configured to avoid these problems.

Signed-off-by: Elijah Newren <[email protected]>
  • Loading branch information
newren committed Aug 1, 2024
1 parent 7f5d212 commit c254044
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions git-filter-repo
Original file line number Diff line number Diff line change
Expand Up @@ -3863,6 +3863,8 @@ class RepoFilter(object):
raise SystemExit(_("git update-ref failed; see above")) # pragma: no cover

# Now remove the origin remote
if b'remote.origin.url' not in self._config_settings:
return
url = self._config_settings[b'remote.origin.url'].decode(errors='replace')
m = _("NOTICE: Removing 'origin' remote; see 'Why is my origin removed?'\n"
" in the manual if you want to push back there.\n"
Expand Down
16 changes: 16 additions & 0 deletions t/t9390-filter-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1977,4 +1977,20 @@ test_expect_success 'failure to run cleanup' '
)
'

test_expect_success 'origin refs without origin remote does not die' '
test_create_repo origin_refs_with_origin_remote &&
(
cd origin_refs_with_origin_remote &&
test_commit numbers &&
git update-ref refs/remotes/origin/svnhead master &&
git filter-repo --force --path-rename numbers.t:values.t &&
git show svnhead:values.t >actual &&
echo numbers >expect &&
test_cmp expect actual
)
'

test_done

0 comments on commit c254044

Please sign in to comment.