knbr13 / gitcs

📈 Command line tool written in Go. It allows developers to scan their local Git repositories and generate a visual contributions graph.
MIT License
116 stars 11 forks source link

Error: Panic "repository does not exist" when running the tool after removing a repository #2

Closed knbr13 closed 1 year ago

knbr13 commented 1 year ago

Description:

The tool scans the .git folders in the provided path and creates a slice of repository paths. It then saves these paths to a file called .gogitlocalstats in the user's home directory.

However, there is a bug in the current implementation. When saving the paths to the file, the tool retrieves the existing paths from the file and adds them to the slice. It checks each path to ensure it is not already present in the slice. If a path is not found in the slice, it is added. Finally, the tool overwrites the contents of the file with the updated slice of paths.

The issue arises when a user removes a repository and then runs the tool again. Since the previous paths from the .gogitlocalstats file are added to the slice without checking their existence, the removed repository's path is still included. This leads to errors when the tool tries to access a non-existent repository, resulting in unexpected panics.

Error Message:

panic: repository does not exist
goroutine 1 [running]:
main.fillCommits(path, otherParams)
        stats.go:38
main.processRepositories(params)
        stats.go:135
main.stats(params)
        stats.go:20
main.main()
        main.go:18

Expected Behavior: The tool should handle repository removals gracefully, without causing a panic. It should ignore non-existent paths in the .gogitlocalstats file and continue processing the remaining repositories.

Steps to Reproduce:

  1. Add repositories to the .gogitlocalstats file. (By running the tool)
  2. Remove one of the repositories from the file system.
  3. Run the tool again.

Thank you!