Skip to content

[Bug] Crashes When Clicking "Rescan Repositories in Default Clone Dir" #434

@ChiahongHong

Description

@ChiahongHong

Since I wasn't sure how you would prefer to address this, I only opened an issue and didn't submit a pull request directly.

Reproduction

  1. Demo directory structure
projects/
├── first/
│   └── .git/
├── second/
│   └── .git/
└── ...
  1. Set the Default Clone Dir to the path where projects is located.
Default Clone Dir
  1. Click Rescan Repositories in Default Clone Dir.

  2. SourceGit will crash and exit immediately.

Cause of the Bug

Ref: 089f24b

var normalizedRoot = rootDir.FullName.Replace("\\", "/");
var prefixLen = normalizedRoot.EndsWith('/') ? normalizedRoot.Length : normalizedRoot.Length + 1;

foreach (var f in founded)
{
    var fullpath = new DirectoryInfo(f);
    var relative = fullpath.Parent!.FullName.Replace("\\", "/").Substring(prefixLen);
    var group = FindOrCreateGroupRecursive(Preference.Instance.RepositoryNodes, relative);
    Preference.Instance.FindOrAddNodeByRepositoryPath(f, group, false);
}

Rescan Repositories

  1. normalizedRoot = /Users/chiahong/Documents/projects
  2. prefixLen = normalizedRoot.Length + 1 = 35
  3. fullpath = /Users/chiahong/Documents/projects/first
  4. fullpath.Parent!.FullName = /Users/chiahong/Documents/projects
  5. .Substring(35) --> index larger than the length of the string

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions