Skip to content

Support expected_old_oid for UserApplyPatch

What does this MR do and why?

Problem

RPCs provide expected_old_oid which is used to verify the ref update and this support was yet to be implemented here.

Solution

Add support for expected_old_oid by passing target_sha as a keyword parameter

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Seeing as this is a process that happens with a combination of the terminal and git itself, there was no quick and simple way to do this but following the step by step here should help. Easies approaches are welcomed.

Setup

  • create a project locally in gdk
  • add a file to your repo file.txt and add content "Hello World" in it
  • git clone your new gdk repo locally
  • cd into your cloned repo directory
  • create a new branch locally via your terminal: git checkout -b patch-test
  • edit your file.txt content to "Bye World"
  • commit your changes: git add file.txt && git commit -m "Patch updates"
  • create the patch file: git format-patch main
  • copy the path of this file

Test

Now we will use code to apply this created patch via our console. We will simulate code being called from CreateMergeRequestHandler

  • open rails console
  • retrieve the id of your created project from gdk UI and use to retrieve your project: project = Project.find(<id>)
  • set your author to the commit author. I will assume root here so author = User.first
  • set your source_branch = 'patch-test' which is the source branch of our patch
  • set your start_branch = 'main' which is our default branch
  • To make use of our patch file locally, we can do this patches = [File.read(<path to patch file>)] Note the surrounding []
  • We can then call result = Commits::CommitPatchService.new(project, author, branch_name: source_branch, patches: patches, start_branch: start_branch).execute to see our patch get applied

Validation

We can now refresh our project page and should see a banner with the new branch and a merge request suggestion with the branch and the changes we made using our patch.

Related to #384013 (closed)

Edited by Olaoluwa Oluro

Merge request reports

Loading