diff --git a/app/services/git/providers/github.rb b/app/services/git/providers/github.rb index 1f94ba5565de9d4d2b23b0cc56285992cad021f7..c90505b371cd075dfee6ffe1138a8c49dbdaa89a 100644 --- a/app/services/git/providers/github.rb +++ b/app/services/git/providers/github.rb @@ -81,16 +81,23 @@ class Git::Providers::Github < Git::Providers::Abstract base_tree_sha = tree[:sha] base_commit_sha = branch_sha commit = nil - batch.each_slice(COMMIT_BATCH_SIZE) do |sub_batch| - puts "Creating commit with #{sub_batch.size} files." - new_tree = client.create_tree repository, sub_batch, base_tree: base_tree_sha - commit = client.create_commit repository, commit_message, new_tree[:sha], base_commit_sha - base_tree_sha = new_tree[:sha] + commits_count = (batch.size / COMMIT_BATCH_SIZE.to_f).ceil + batch.each_slice(COMMIT_BATCH_SIZE).with_index do |sub_batch, i| + sub_commit_message = commit_message + sub_commit_message += " (#{i+1}/#{commits_count})" if commits_count > 1 + commit = create_sub_commit(sub_batch, sub_commit_message, base_tree_sha, base_commit_sha) + base_tree_sha = commit[:tree][:sha] base_commit_sha = commit[:sha] end commit end + def create_sub_commit(sub_batch, sub_commit_message, base_tree_sha, base_commit_sha) + puts "Creating commit with #{sub_batch.size} files." + new_tree = client.create_tree repository, sub_batch, base_tree: base_tree_sha + client.create_commit repository, sub_commit_message, new_tree[:sha], base_commit_sha + end + def computed_sha(string) # Git SHA-1 is calculated from the String "blob <length>\x00<contents>" # Source: https://alblue.bandlem.com/2011/08/git-tip-of-week-objects.html