Fix push rules validation on initial push
Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/356094 **Problem** Push rules validations for files don't work on the first push to the empty repository. The root cause is a `git diff-tree` behavior for an initial commit. It returns an empty result if we provide a sha of the initial commit, but it works correctly for all following commits. **Solution** Use tree ids to get the diff of the initial commit. Git has a special empty tree id `4b825dc642cb6eb9a060e54bf8d69288fbee4904` that corresponds to the empty repository state. Instead of `git diff-tree <commit_id>` we can request a diff between two trees: `git diff-tree <empty_tree_id> <commit_tree_id>`. This approach returns a correct diff for the initial commit.
显示
- config/feature_flags/development/verify_push_rules_for_first_commit.yml 8 个添加, 0 个删除..._flags/development/verify_push_rules_for_first_commit.yml
- ee/spec/lib/gitlab/checks/diff_check_spec.rb 36 个添加, 0 个删除ee/spec/lib/gitlab/checks/diff_check_spec.rb
- ee/spec/support/shared_contexts/push_rules_checks_shared_context.rb 3 个添加, 3 个删除...pport/shared_contexts/push_rules_checks_shared_context.rb
- lib/gitlab/checks/diff_check.rb 24 个添加, 4 个删除lib/gitlab/checks/diff_check.rb
- lib/gitlab/git/commit.rb 6 个添加, 0 个删除lib/gitlab/git/commit.rb
- lib/gitlab/git/diff_tree.rb 30 个添加, 0 个删除lib/gitlab/git/diff_tree.rb
- lib/gitlab/git/repository.rb 4 个添加, 6 个删除lib/gitlab/git/repository.rb
- lib/gitlab/gitaly_client/commit_service.rb 21 个添加, 8 个删除lib/gitlab/gitaly_client/commit_service.rb
- spec/lib/gitlab/git/commit_spec.rb 12 个添加, 2 个删除spec/lib/gitlab/git/commit_spec.rb
- spec/lib/gitlab/git/diff_tree_spec.rb 30 个添加, 0 个删除spec/lib/gitlab/git/diff_tree_spec.rb
- spec/lib/gitlab/git/repository_spec.rb 19 个添加, 7 个删除spec/lib/gitlab/git/repository_spec.rb
- spec/lib/gitlab/gitaly_client/commit_service_spec.rb 37 个添加, 1 个删除spec/lib/gitlab/gitaly_client/commit_service_spec.rb
加载中
想要评论请 注册 或 登录