@@ -704,6 +704,7 @@ def commit_dir(user, path, message, branch)
704
704
options [ :commit ] = {
705
705
message : message ,
706
706
branch : ref ,
707
+ update_ref : false ,
707
708
}
708
709
709
710
raw_repository . mkdir ( path , options )
@@ -719,6 +720,7 @@ def commit_file(user, path, content, message, branch, update)
719
720
options [ :commit ] = {
720
721
message : message ,
721
722
branch : ref ,
723
+ update_ref : false ,
722
724
}
723
725
724
726
options [ :file ] = {
@@ -739,7 +741,8 @@ def remove_file(user, path, message, branch)
739
741
options [ :author ] = committer
740
742
options [ :commit ] = {
741
743
message : message ,
742
- branch : ref
744
+ branch : ref ,
745
+ update_ref : false ,
743
746
}
744
747
745
748
options [ :file ] = {
@@ -779,11 +782,10 @@ def merge(user, merge_request, options = {})
779
782
merge_index = rugged . merge_commits ( our_commit , their_commit )
780
783
return false if merge_index . conflicts?
781
784
782
- commit_with_hooks ( user , merge_request . target_branch ) do | tmp_ref |
785
+ commit_with_hooks ( user , merge_request . target_branch ) do
783
786
actual_options = options . merge (
784
787
parents : [ our_commit , their_commit ] ,
785
788
tree : merge_index . write_tree ( rugged ) ,
786
- update_ref : tmp_ref
787
789
)
788
790
789
791
commit_id = Rugged ::Commit . create ( rugged , actual_options )
@@ -798,15 +800,14 @@ def revert(user, commit, base_branch, revert_tree_id = nil)
798
800
799
801
return false unless revert_tree_id
800
802
801
- commit_with_hooks ( user , base_branch ) do | ref |
803
+ commit_with_hooks ( user , base_branch ) do
802
804
committer = user_to_committer ( user )
803
805
source_sha = Rugged ::Commit . create ( rugged ,
804
806
message : commit . revert_message ,
805
807
author : committer ,
806
808
committer : committer ,
807
809
tree : revert_tree_id ,
808
- parents : [ rugged . lookup ( source_sha ) ] ,
809
- update_ref : ref )
810
+ parents : [ rugged . lookup ( source_sha ) ] )
810
811
end
811
812
end
812
813
@@ -816,7 +817,7 @@ def cherry_pick(user, commit, base_branch, cherry_pick_tree_id = nil)
816
817
817
818
return false unless cherry_pick_tree_id
818
819
819
- commit_with_hooks ( user , base_branch ) do | ref |
820
+ commit_with_hooks ( user , base_branch ) do
820
821
committer = user_to_committer ( user )
821
822
source_sha = Rugged ::Commit . create ( rugged ,
822
823
message : commit . message ,
@@ -827,8 +828,7 @@ def cherry_pick(user, commit, base_branch, cherry_pick_tree_id = nil)
827
828
} ,
828
829
committer : committer ,
829
830
tree : cherry_pick_tree_id ,
830
- parents : [ rugged . lookup ( source_sha ) ] ,
831
- update_ref : ref )
831
+ parents : [ rugged . lookup ( source_sha ) ] )
832
832
end
833
833
end
834
834
@@ -929,20 +929,6 @@ def fetch_ref(source_path, source_ref, target_ref)
929
929
Gitlab ::Popen . popen ( args , path_to_repo )
930
930
end
931
931
932
- def with_tmp_ref ( oldrev = nil )
933
- random_string = SecureRandom . hex
934
- tmp_ref = "refs/tmp/#{ random_string } /head"
935
-
936
- if oldrev && !Gitlab ::Git . blank_ref? ( oldrev )
937
- rugged . references . create ( tmp_ref , oldrev )
938
- end
939
-
940
- # Make commit in tmp ref
941
- yield ( tmp_ref )
942
- ensure
943
- rugged . references . delete ( tmp_ref ) rescue nil
944
- end
945
-
946
932
def commit_with_hooks ( current_user , branch )
947
933
update_autocrlf_option
948
934
@@ -955,33 +941,31 @@ def commit_with_hooks(current_user, branch)
955
941
oldrev = target_branch . target
956
942
end
957
943
958
- with_tmp_ref ( oldrev ) do |tmp_ref |
959
- # Make commit in tmp ref
960
- newrev = yield ( tmp_ref )
944
+ # Make commit
945
+ newrev = yield ( ref )
961
946
962
- unless newrev
963
- raise CommitError . new ( 'Failed to create commit' )
964
- end
947
+ unless newrev
948
+ raise CommitError . new ( 'Failed to create commit' )
949
+ end
950
+
951
+ GitHooksService . new . execute ( current_user , path_to_repo , oldrev , newrev , ref ) do
952
+ if was_empty || !target_branch
953
+ # Create branch
954
+ rugged . references . create ( ref , newrev )
955
+ else
956
+ # Update head
957
+ current_head = find_branch ( branch ) . target
965
958
966
- GitHooksService . new . execute ( current_user , path_to_repo , oldrev , newrev , ref ) do
967
- if was_empty || !target_branch
968
- # Create branch
969
- rugged . references . create ( ref , newrev )
959
+ # Make sure target branch was not changed during pre-receive hook
960
+ if current_head == oldrev
961
+ rugged . references . update ( ref , newrev )
970
962
else
971
- # Update head
972
- current_head = find_branch ( branch ) . target
973
-
974
- # Make sure target branch was not changed during pre-receive hook
975
- if current_head == oldrev
976
- rugged . references . update ( ref , newrev )
977
- else
978
- raise CommitError . new ( 'Commit was rejected because branch received new push' )
979
- end
963
+ raise CommitError . new ( 'Commit was rejected because branch received new push' )
980
964
end
981
965
end
982
-
983
- newrev
984
966
end
967
+
968
+ newrev
985
969
end
986
970
987
971
def ls_files ( ref )
0 commit comments