Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
fix: remove file from git tree when delete
Browse files Browse the repository at this point in the history
Previously, it was failing when the file was deleted on fetching the file content. So updated the code to now remove file from git tree if the path doesn't exist.
  • Loading branch information
Muhammad Soban Javed committed Aug 31, 2023
1 parent 3197db4 commit f443f1e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions jenkins/github_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,12 @@ def update_list_of_files(self, repository, repo_root, file_path_list, commit_mes
input_trees_list = []
base_git_tree = repository.get_git_tree(sha)
for file_path in file_path_list:
content = self.get_file_contents(repo_root, file_path)
input_tree = InputGitTreeElement(file_path, "100644", "blob", content=content)
if os.path.exists(os.path.join(repo_root, file_path)):
content = self.get_file_contents(repo_root, file_path)
input_tree = InputGitTreeElement(file_path, "100644", "blob", content=content)
else:
# Remove file from git tree as the file is removed
input_tree = InputGitTreeElement(file_path, "100644", "blob", sha=None)
input_trees_list.append(input_tree)
if len(input_trees_list) > 0:
new_git_tree = repository.create_git_tree(input_trees_list, base_tree=base_git_tree)
Expand Down

0 comments on commit f443f1e

Please sign in to comment.