StringIndexOutOfBoundsException if repository named .git exists
				
					
				
			If a repository named `.git`, i.e. created with `git init --bare .git`, exists in the root of the `$gerrit_site/git` folder, the `prefix` is an empty string and StringIndexOutOfBoundsException occurs when attempting to get a substring with `prefix.length() - 1`. When scanning for repositories, ignore any that are named only `.git` anywhere in the tree. Bug: issue 2017 Change-Id: I72900589c1f187b79f9d64825d469394fd504f89
This commit is contained in:
		
				
					committed by
					
						
						Shawn Pearce
					
				
			
			
				
	
			
			
			
						parent
						
							2b0889dc80
						
					
				
				
					commit
					7c1d5cb399
				
			@@ -357,7 +357,9 @@ public class LocalDiskRepositoryManager implements GitRepositoryManager {
 | 
			
		||||
 | 
			
		||||
    for (File f : ls) {
 | 
			
		||||
      String fileName = f.getName();
 | 
			
		||||
      if (FileKey.isGitRepository(f, FS.DETECTED)) {
 | 
			
		||||
      if (fileName.equals(Constants.DOT_GIT)) {
 | 
			
		||||
        // Skip repositories named only `.git`
 | 
			
		||||
      } else if (FileKey.isGitRepository(f, FS.DETECTED)) {
 | 
			
		||||
        Project.NameKey nameKey = getProjectName(prefix, fileName);
 | 
			
		||||
        if (isUnreasonableName(nameKey)) {
 | 
			
		||||
          log.warn("Ignoring unreasonably named repository " + f.getAbsolutePath());
 | 
			
		||||
@@ -374,10 +376,7 @@ public class LocalDiskRepositoryManager implements GitRepositoryManager {
 | 
			
		||||
  private Project.NameKey getProjectName(final String prefix,
 | 
			
		||||
      final String fileName) {
 | 
			
		||||
    final String projectName;
 | 
			
		||||
    if (fileName.equals(Constants.DOT_GIT)) {
 | 
			
		||||
      projectName = prefix.substring(0, prefix.length() - 1);
 | 
			
		||||
 | 
			
		||||
    } else if (fileName.endsWith(Constants.DOT_GIT_EXT)) {
 | 
			
		||||
    if (fileName.endsWith(Constants.DOT_GIT_EXT)) {
 | 
			
		||||
      int newLen = fileName.length() - Constants.DOT_GIT_EXT.length();
 | 
			
		||||
      projectName = prefix + fileName.substring(0, newLen);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user