mirror of
				https://github.com/fluxcd/flux2.git
				synced 2025-10-31 08:17:19 +08:00 
			
		
		
		
	Make the Git ref required
Remove the default branch value from `flux create source git` and validate that one of the ref options are specified. Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
		| @ -122,7 +122,7 @@ var sourceGitArgs = newSourceGitFlags() | |||||||
|  |  | ||||||
| func init() { | func init() { | ||||||
| 	createSourceGitCmd.Flags().StringVar(&sourceGitArgs.url, "url", "", "git address, e.g. ssh://git@host/org/repository") | 	createSourceGitCmd.Flags().StringVar(&sourceGitArgs.url, "url", "", "git address, e.g. ssh://git@host/org/repository") | ||||||
| 	createSourceGitCmd.Flags().StringVar(&sourceGitArgs.branch, "branch", "master", "git branch") | 	createSourceGitCmd.Flags().StringVar(&sourceGitArgs.branch, "branch", "", "git branch") | ||||||
| 	createSourceGitCmd.Flags().StringVar(&sourceGitArgs.tag, "tag", "", "git tag") | 	createSourceGitCmd.Flags().StringVar(&sourceGitArgs.tag, "tag", "", "git tag") | ||||||
| 	createSourceGitCmd.Flags().StringVar(&sourceGitArgs.semver, "tag-semver", "", "git tag semver range") | 	createSourceGitCmd.Flags().StringVar(&sourceGitArgs.semver, "tag-semver", "", "git tag semver range") | ||||||
| 	createSourceGitCmd.Flags().StringVarP(&sourceGitArgs.username, "username", "u", "", "basic authentication username") | 	createSourceGitCmd.Flags().StringVarP(&sourceGitArgs.username, "username", "u", "", "basic authentication username") | ||||||
| @ -166,6 +166,10 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error { | |||||||
| 		return fmt.Errorf("git URL scheme '%s' not supported, can be: ssh, http and https", u.Scheme) | 		return fmt.Errorf("git URL scheme '%s' not supported, can be: ssh, http and https", u.Scheme) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	if sourceGitArgs.branch == "" && sourceGitArgs.tag == "" && sourceGitArgs.semver == "" { | ||||||
|  | 		return fmt.Errorf("a Git ref is required, use one of the following: --branch, --tag or --tag-semver") | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	if sourceGitArgs.caFile != "" && u.Scheme == "ssh" { | 	if sourceGitArgs.caFile != "" && u.Scheme == "ssh" { | ||||||
| 		return fmt.Errorf("specifing a CA file is not supported for Git over SSH") | 		return fmt.Errorf("specifing a CA file is not supported for Git over SSH") | ||||||
| 	} | 	} | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Stefan Prodan
					Stefan Prodan