Ensure target_sha is always set, remove skip_target_sha
What does this MR do and why?
This MR ensures that target_sha
is always set correctly when committing files. Previously, we used skip_target_sha
to avoid setting it in certain cases, but now we follow the recommended approach of setting target_sha
to the branch’s latest commit SHA or a blank reference when needed. This also simplifies the logic by removing skip_target_sha
.
This MR aims to solve the issue #517122
Behind Feature Flag #520058
How to set up and validate locally
- Open Rails Console and Fetch the Project
-
Find the project
Project = Project.find(3)
-
Check if the Repository exits
puts project.repository.exists?
Expected: Should return true meaning the repository exists.
-
Define a test branch name
branch_name = 'bug-replication-test'
-
Check if the branch exists
puts project.repository.branch_exists?(branch_name)
Expected: Should return false confirming that the branch does not exist.
-
Get the repository object:
repo = project.repository
-
Attempt to commit a file:
repo.commit_files( User.find_by_username('root'),
branch_name: branch_name, message: 'Bug replication test', actions: [{ action: 'create', file_path: 'test_bug.txt', content: 'Testing bug scenario' }] ) -
If the fix works the commit should succeed and the branch should be created.
-
If the bug still exists the commit should fail due to a missing target_sha.
-
Check if the branch now exists:
puts project.repository.branch_exists?(branch_name)
Expected: Should return true confirming that the branch was created and the commit was successful.
-