Skip to content

Conversation

@eranturgeman
Copy link
Contributor

  • All tests passed. If this feature is not already covered by the tests, I added new tests.
  • This pull request is on the dev branch.
  • I used gofmt for formatting the code before submitting the pull request.
  • Update documentation about new features / new supported technologies

This PR fixes 2 things:

  1. names of functions that were incorrect/ not very clear
  2. potential bug that can cause the utilized gitManager to point its local git repository (.git) to a deleted repo, leaving it in an invalid state
    Explanation: Since we can iterate several branches in scan-repo, for each branch we work in a temp dir and return to the original dir at the end. When returning to the original dir we set the cur wd to the original dir and delete the temp one. I noticed that we missed setting the .git repo to the original on. This may cause if some failure happens to leave the gitManager pointing to a .git repository that no longer exists

@eranturgeman eranturgeman added bug Something isn't working safe to test Approve running integration tests on a pull request labels Dec 30, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Dec 30, 2025
@github-actions
Copy link
Contributor

👍 Frogbot scanned this pull request and did not find any new security issues.


@eranturgeman eranturgeman requested a review from eyalk007 January 1, 2026 07:40
}

func (gm *GitManager) SetLocalRepository() error {
// Sets the current working dir as the local git repository
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment
func name is self explanatory

sr.baseWd = repoDir
defer func() {
// On dry run don't delete the folder as we want to validate results
if sr.dryRun {
Copy link
Collaborator

@eyalk007 eyalk007 Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not your code but if you like to(if not stop reading and resolve):

this whole dry run concept is wrong

dry run is used purely for tests

and this is test logic that is leaking into production code

if you want to fix it you can extract a GitClient interface and use dependency injection.

}

func (sr *ScanRepositoryCmd) checkoutToBranch() (tempWd string, restoreDir func() error, err error) {
// This func switches to a newly created or provided temp dir for the the current execution in order to keep the user's working dir clean.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in comment but remove it anyway

generally we don't want comments

comments are for either one of these 3 things:

  1. A temporary situation that will change in the future - Usually we add a TODO for a patch that cant be done.

  2. A misguided approach due to a third party source - for example the cli returns a bad object and we need to parse and change it to fit what we do.

  3. An unclear business logic - when the logic the code performs contradicts straightforward logic,
    We add a comment that explains the why the code is doing what it is doing and not the what.

if err != nil {
return
}
// Set the current copied local dir as the local git repository we are working with
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not your code but please remove comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants