mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-31 06:21:11 +00:00 
			
		
		
		
	- Resolves forgejo/discussions#324 - Remove all checks of `CheckGitVersionAtLeast` that checked for a version below 2.34.1 - The version was chosen because Debian stable supports 2.39.5 and Ubuntu 22.04 LTS supports 2.34.1 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8328 Reviewed-by: 0ko <0ko@noreply.codeberg.org> Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
		
			
				
	
	
		
			42 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2021 The Gitea Authors. All rights reserved.
 | |
| // SPDX-License-Identifier: MIT
 | |
| 
 | |
| package git
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"strings"
 | |
| 
 | |
| 	giturl "forgejo.org/modules/git/url"
 | |
| )
 | |
| 
 | |
| // GetRemoteAddress returns remote url of git repository in the repoPath with special remote name
 | |
| func GetRemoteAddress(ctx context.Context, repoPath, remoteName string) (string, error) {
 | |
| 	result, _, err := NewCommand(ctx, "remote", "get-url").AddDynamicArguments(remoteName).RunStdString(&RunOpts{Dir: repoPath})
 | |
| 	if err != nil {
 | |
| 		return "", err
 | |
| 	}
 | |
| 
 | |
| 	if len(result) > 0 {
 | |
| 		result = result[:len(result)-1]
 | |
| 	}
 | |
| 	return result, nil
 | |
| }
 | |
| 
 | |
| // GetRemoteURL returns the url of a specific remote of the repository.
 | |
| func GetRemoteURL(ctx context.Context, repoPath, remoteName string) (*giturl.GitURL, error) {
 | |
| 	addr, err := GetRemoteAddress(ctx, repoPath, remoteName)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return giturl.Parse(addr)
 | |
| }
 | |
| 
 | |
| // IsRemoteNotExistError checks the prefix of the error message to see whether a remote does not exist.
 | |
| func IsRemoteNotExistError(err error) bool {
 | |
| 	// see: https://github.com/go-gitea/gitea/issues/32889#issuecomment-2571848216
 | |
| 	// Should not add space in the end, sometimes git will add a `:`
 | |
| 	prefix1 := "exit status 128 - fatal: No such remote" // git < 2.30
 | |
| 	prefix2 := "exit status 2 - error: No such remote"   // git >= 2.30
 | |
| 	return strings.HasPrefix(err.Error(), prefix1) || strings.HasPrefix(err.Error(), prefix2)
 | |
| }
 |