ManageIQ / manageiq

ManageIQ Open-Source Management Platform
https://manageiq.org
Apache License 2.0
1.34k stars 897 forks source link

old branches cleanup for Git-based domain #23087

Closed Fryguy closed 2 months ago

Fryguy commented 3 months ago

Discussed in https://github.com/orgs/ManageIQ/discussions/23085

Originally posted by **ebilbil** July 12, 2024 Hi all, We currently using Petrosian release and we can see in the window "refreshing branch for Git-based domain" a lot of branches which no longer exist in our Git repo. Is it possible to cleanup these branches from the list? ![image](https://github.com/user-attachments/assets/19aeb41e-efb8-4861-92fd-05a51101f229)
Fryguy commented 3 months ago

When we refresh a repository, we should prune branches that no longer exist on the remote.

One thing we have to be careful of, however, is that if a branch is still in use by the product (in automate, or even in workflows, ansible, etc), that we don't remove that branch, but perhaps log a warning.

jaisejose1123 commented 3 months ago

Steps Done for debugging

updated the git_repository_id with an existing git repository Initially, the git_repository_id in the newly created domain will be nil. Update the git_repository_id with the existing Git repository.

Let me try to find more information on how to achieve this. @Fryguy do you know where this information is stored in our db?

jaisejose1123 commented 3 months ago

@Fryguy I've made some code changes in this file to see the “Refresh with a new branch or tag” button. How can we view this button in the UI without modifying the code?

agrare commented 3 months ago

@jaisejose1123 the UI code you've linked to just displays what is in the repository, the issue here is that the local clone of the repo we have has out-of-date refs.

Here is where a GitRepository refresh is done https://github.com/ManageIQ/manageiq/blob/2b57f9a42ad54a0255920c790c1f9dccce9ce26f/app/models/git_repository.rb#L51-L59 so I'm assuming that the fetch_and_merge from GitWorktree should also prune local refs that don't exist on the remote.

Fryguy commented 3 months ago

@jaisejose1123 Right - create a git branch, then refresh from the UI, then delete the git branch, then refresh from the UI again. The branch should go away, but the reported bug is that it doesn't

jaisejose1123 commented 2 months ago

Created a PR please review https://github.com/ManageIQ/manageiq/pull/23115

Fryguy commented 2 months ago

Fixed in #23115