fix(git): check destination emptiness without full readdir
Avoid reading an entire directory just to determine if clone destination is empty. Use ReadDir(1) to detect emptiness efficiently while preserving error behavior for non-empty and inaccessible paths.
Description
This PR improves clone destination validation in pkg/lib/external/git/clone.go.
Previously, checkDestination used os.ReadDir(path) to determine whether a directory is empty, which reads the entire directory contents even though only an empty/non-empty check is needed.
This change replaces that with a one-entry probe:
os.Open(path)ReadDir(1)
Behavior is preserved:
err == nil=> directory is non-emptyerr == io.EOF=> directory is empty- other errors => return wrapped inspection error
Validation:
go test ./pkg/lib/external/git(pass)
Linked issues
N/A
Can you add the sign-off messages to your commits. Click on the failing DCO check above for how to instructions.
@AdeshDeshmukh please fix failing DCO check before we can review this.
@amisevsk Thank you for your thorough review and valuable suggestions. I've removed the annotation migration changes as you recommended — the PR now focuses solely on the clone.go directory emptiness check. I've also resolved the merge conflicts and ensured DCO compliance. Would appreciate a re-review when you a bandwidth. PTAL