From 3f1947982ba69930ef2d89afa895ac2296f63405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com> Date: Mon, 19 Dec 2022 10:56:57 +0100 Subject: [PATCH] fix sync existing remote file --- app/services/git/providers/github.rb | 6 ++++-- app/services/git/providers/gitlab.rb | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/services/git/providers/github.rb b/app/services/git/providers/github.rb index 2bf52bf8d..ecf9169e9 100644 --- a/app/services/git/providers/github.rb +++ b/app/services/git/providers/github.rb @@ -9,10 +9,12 @@ class Git::Providers::Github < Git::Providers::Abstract end def update_file(path, previous_path, content) - file = tree_item_at_path(previous_path) + # Handle newly created GitFiles which update existing remote files while having blank previous_path. + path_to_check = previous_path.present? ? previous_path : path + file = tree_item_at_path(path_to_check) return if file.nil? batch << { - path: previous_path, + path: path_to_check, mode: file[:mode], type: file[:type], sha: nil diff --git a/app/services/git/providers/gitlab.rb b/app/services/git/providers/gitlab.rb index 73f4c87dd..23cfaa330 100644 --- a/app/services/git/providers/gitlab.rb +++ b/app/services/git/providers/gitlab.rb @@ -11,8 +11,7 @@ class Git::Providers::Gitlab < Git::Providers::Abstract def update_file(path, previous_path, content) file = find previous_path - return if file.nil? - if previous_path != path + if file.present? && previous_path != path batch << { action: 'move', file_path: path, -- GitLab