Skip to content
Snippets Groups Projects

dim: Disallow remote branch deletions with 'dim push'

Open Ashutosh Dixit requested to merge adixit/maintainer-tools:master into master

An inadvertent 'dim push -d' can delete remote branches. Disallow such remote branch deletions.

v2: s/

@/
*/ for shellcheck SC2199

Signed-off-by: Ashutosh Dixit ashutosh.dixit@intel.com

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Should we abort or should we confirm [y/N] ? @jani @sima thoughts?

  • This one's old, fell between the cracks...

    The first problem is, "$*" == *"-d"* maches anything that has -d in it. Including, say, --dry-run, but happily (likely by coincidence) also --delete. How thorough or accurate do we want this to be?

    Perhaps check for any extra options being passed to git push, and prompt for confirmation?

  • I recently had this issue when performing a dim push-branch drm-misc-next -d.

    $ ../maintainer-tools/dim push-branch drm-misc-next -d
    remote: GitLab: You are not allowed to delete protected branches from this project. Only a project maintainer or owner can delete a protected branch.
    To ssh://gitlab.freedesktop.org/drm/misc/kernel.git
     ! [remote rejected]           drm-misc-next (pre-receive hook declined)
    error: failed to push some refs to 'ssh://gitlab.freedesktop.org/drm/misc/kernel.git'

    How about using if [[ " $* " == [[:space:]]-d[[:space:]] ]]?

  • Here's an alternative idea: Just do not pass "$@" to git by default. At all.

    Add a new dim parameter --passthrough-args or similar, and require that to pass the rest of the params to git or other shell commands. Warn if "$@" is present without the parameter.

    This avoids accidents in the common cases, and enables full flexibility when required. And avoids the complexity of trying to parse "dangerous" git parameters.

  • @adixit, do you plan to work on Jani's suggestion?

Please register or sign in to reply
Loading