mirror of
				https://git.proxmox.com/git/libgit2
				synced 2025-11-04 14:08:17 +00:00 
			
		
		
		
	Enable authenticated clones in network sample
This commit is contained in:
		
							parent
							
								
									24393ea6d3
								
							
						
					
					
						commit
						2b10a2b0e8
					
				@ -47,6 +47,21 @@ static void checkout_progress(const char *path, size_t cur, size_t tot, void *pa
 | 
			
		||||
	print_progress(pd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int cred_acquire(git_cred **out, const char *url, unsigned int allowed_types, void *payload)
 | 
			
		||||
{
 | 
			
		||||
	char username[128] = {0};
 | 
			
		||||
	char password[128] = {0};
 | 
			
		||||
 | 
			
		||||
	printf("Username: ");
 | 
			
		||||
	scanf("%s", username);
 | 
			
		||||
 | 
			
		||||
	/* Yup. Right there on your terminal. Careful where you copy/paste output. */
 | 
			
		||||
	printf("Password: ");
 | 
			
		||||
	scanf("%s", password);
 | 
			
		||||
 | 
			
		||||
	return git_cred_userpass_plaintext_new(out, username, password);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int do_clone(git_repository *repo, int argc, char **argv)
 | 
			
		||||
{
 | 
			
		||||
	progress_data pd;
 | 
			
		||||
@ -71,7 +86,7 @@ int do_clone(git_repository *repo, int argc, char **argv)
 | 
			
		||||
	memset(&pd, 0, sizeof(pd));
 | 
			
		||||
	checkout_opts.progress_payload = &pd;
 | 
			
		||||
 | 
			
		||||
	// Create the origin remote
 | 
			
		||||
	// Create the origin remote, and set up for auth
 | 
			
		||||
	error = git_remote_new(&origin, NULL, "origin", url, GIT_REMOTE_DEFAULT_FETCH);
 | 
			
		||||
	if (error != 0) {
 | 
			
		||||
		const git_error *err = giterr_last();
 | 
			
		||||
@ -79,6 +94,7 @@ int do_clone(git_repository *repo, int argc, char **argv)
 | 
			
		||||
		else printf("ERROR %d: no detailed info\n", error);
 | 
			
		||||
		return error;
 | 
			
		||||
	}
 | 
			
		||||
	git_remote_set_cred_acquire_cb(origin, cred_acquire, NULL);
 | 
			
		||||
 | 
			
		||||
	// Do the clone
 | 
			
		||||
	error = git_clone(&cloned_repo, origin, path, &checkout_opts, &fetch_progress, &pd);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user