# HG changeset patch # User RhodeCode Admin # Date 2024-01-02 15:43:17 # Node ID 65ddf04b88d24743185a00f1d6deabeb1da5f7aa # Parent 1ecdda6474c4d3d7ef8cf11521dfab743d1d874f fix(git): fixed strip command to always require a valid branch name for git. unless specific branch is given git strip doesn't really work fine 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 @@
+ + %if c.rhodecode_db_repo.repo_type == 'git': + + %endif +
${_('Add another commit')}
@@ -47,16 +53,32 @@ addNew = function(number){ $('#plus_icon-'+number).detach(); number++; - var input = '
'+ - ''+ - '
'+ - '${_('Add another commit')}'+ - '
'+ - '
'+ + %if c.rhodecode_db_repo.repo_type == 'git': + var input = '
' + + '' + + '' + + '
' + + '${_('Add another commit')}' + + '
' + + '
' + minus + - '
' + - '
'; + '
' + + '
'; + %else: + var input = '
'+ + ''+ + '
'+ + '${_('Add another commit')}'+ + '
'+ + '
'+ + minus + + '
' + + '
'; + %endif + $('#change_body').append(input); plus_leaf++; }; @@ -135,12 +157,13 @@ checkCommits = function() { '{1}' + '
' + 'author: {2}\n' + - 'description: {3}' + + 'description: {3}\n' + + 'branch: {4}' + '
' + '').format( value.rev, "${_(' commit verified positive')}", - value.author, value.comment + value.author, value.comment, value.branch ); result += verifiedHtml; }