diff --git a/rhodecode/apps/repository/views/repo_strip.py b/rhodecode/apps/repository/views/repo_strip.py --- a/rhodecode/apps/repository/views/repo_strip.py +++ b/rhodecode/apps/repository/views/repo_strip.py @@ -53,15 +53,17 @@ class RepoStripView(RepoAppView): data = {} rp = self.request.POST for i in range(1, 11): - chset = 'changeset_id-%d' % (i,) - check = rp.get(chset) + changeset_id_key = f'changeset_id-{i}' + changeset_id_branch_key = f'changeset_id_branch-{i}' + check = rp.get(changeset_id_key) if check: - data[i] = self.db_repo.get_commit(rp[chset]) + data[i] = self.db_repo.get_commit(rp[changeset_id_key]) if isinstance(data[i], EmptyCommit): - data[i] = {'rev': None, 'commit': h.escape(rp[chset])} + data[i] = {'rev': None, 'commit': h.escape(rp[changeset_id_key])} else: - data[i] = {'rev': data[i].raw_id, 'branch': data[i].branch, + rp_branch = rp.get(changeset_id_branch_key) + data[i] = {'rev': data[i].raw_id, 'branch': data[i].branch or rp_branch, 'author': h.escape(data[i].author), 'comment': h.escape(data[i].message)} else: @@ -78,6 +80,7 @@ class RepoStripView(RepoAppView): user = self._rhodecode_user rp = self.request.POST data = {} + for idx in rp: commit = json.loads(rp[idx]) # If someone put two times the same branch @@ -98,5 +101,5 @@ class RepoStripView(RepoAppView): except Exception as e: data[commit['rev']] = False log.debug('Stripped commit %s from repo `%s` failed by %s, exeption %s', - commit['rev'], self.db_repo_name, user, e.message) + commit['rev'], self.db_repo_name, user, e) return data diff --git a/rhodecode/lib/vcs/backends/git/repository.py b/rhodecode/lib/vcs/backends/git/repository.py --- a/rhodecode/lib/vcs/backends/git/repository.py +++ b/rhodecode/lib/vcs/backends/git/repository.py @@ -583,9 +583,12 @@ class GitRepository(BaseRepository): if commit.merge: raise Exception('Cannot reset to merge commit') + if not branch_name: + raise ValueError(f'git strip requires a valid branch name, got {branch_name} instead') + # parent is going to be the new head now commit = commit.parents[0] - self._remote.set_refs('refs/heads/%s' % branch_name, commit.raw_id) + self._remote.update_refs(f'refs/heads/{branch_name}', commit.raw_id) # clear cached properties self._invalidate_prop_cache('commit_ids') diff --git a/rhodecode/templates/admin/repos/repo_edit_strip.mako b/rhodecode/templates/admin/repos/repo_edit_strip.mako --- a/rhodecode/templates/admin/repos/repo_edit_strip.mako +++ b/rhodecode/templates/admin/repos/repo_edit_strip.mako @@ -14,6 +14,12 @@