mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-04 08:30:39 +00:00
feat(git): Add authentication to clone, fetch, and pull.
This commit is contained in:
@@ -20,6 +20,7 @@ import git from 'isomorphic-git';
|
||||
import http from 'isomorphic-git/http/web';
|
||||
import { SHOW_USAGE } from '../help.js';
|
||||
import path from 'path-browserify';
|
||||
import { authentication_options, Authenticator } from '../auth.js';
|
||||
|
||||
export default {
|
||||
name: 'clone',
|
||||
@@ -46,6 +47,7 @@ export default {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
...authentication_options,
|
||||
},
|
||||
},
|
||||
execute: async (ctx) => {
|
||||
@@ -74,6 +76,15 @@ export default {
|
||||
throw SHOW_USAGE;
|
||||
}
|
||||
|
||||
if (!options.username !== !options.password) {
|
||||
stderr('Please specify both --username and --password, or neither');
|
||||
return 1;
|
||||
}
|
||||
const authenticator = new Authenticator({
|
||||
username: options.username,
|
||||
password: options.password,
|
||||
});
|
||||
|
||||
let repo_path;
|
||||
if (directory) {
|
||||
repo_path = path.resolve(env.PWD, directory);
|
||||
@@ -113,6 +124,7 @@ export default {
|
||||
singleBranch: options['single-branch'],
|
||||
noTags: options['no-tags'],
|
||||
onMessage: (message) => { stdout(message); },
|
||||
...authenticator.get_auth_callbacks(stderr),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import git from 'isomorphic-git';
|
||||
import http from 'isomorphic-git/http/web';
|
||||
import { determine_fetch_remote, find_repo_root } from '../git-helpers.js';
|
||||
import { SHOW_USAGE } from '../help.js';
|
||||
import { authentication_options, Authenticator } from '../auth.js';
|
||||
|
||||
export default {
|
||||
name: 'fetch',
|
||||
@@ -35,7 +36,8 @@ export default {
|
||||
description: 'Fetch all remotes.',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
}
|
||||
},
|
||||
...authentication_options,
|
||||
},
|
||||
},
|
||||
execute: async (ctx) => {
|
||||
@@ -54,6 +56,15 @@ export default {
|
||||
gitdir,
|
||||
});
|
||||
|
||||
if (!options.username !== !options.password) {
|
||||
stderr('Please specify both --username and --password, or neither');
|
||||
return 1;
|
||||
}
|
||||
const authenticator = new Authenticator({
|
||||
username: options.username,
|
||||
password: options.password,
|
||||
});
|
||||
|
||||
if (options.all) {
|
||||
for (const { remote, url } of remotes) {
|
||||
stdout(`Fetching ${remote}\nFrom ${url}`);
|
||||
@@ -66,6 +77,7 @@ export default {
|
||||
gitdir,
|
||||
remote,
|
||||
onMessage: (message) => { stdout(message); },
|
||||
...authenticator.get_auth_callbacks(stderr),
|
||||
});
|
||||
}
|
||||
return;
|
||||
@@ -83,6 +95,7 @@ export default {
|
||||
gitdir,
|
||||
...remote_data,
|
||||
onMessage: (message) => { stdout(message); },
|
||||
...authenticator.get_auth_callbacks(stderr),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import git from 'isomorphic-git';
|
||||
import http from 'isomorphic-git/http/web';
|
||||
import { determine_fetch_remote, find_repo_root } from '../git-helpers.js';
|
||||
import { SHOW_USAGE } from '../help.js';
|
||||
import { authentication_options, Authenticator } from '../auth.js';
|
||||
|
||||
export default {
|
||||
name: 'pull',
|
||||
@@ -43,6 +44,7 @@ export default {
|
||||
description: 'Only update history if a fast-forward is possible.',
|
||||
type: 'boolean',
|
||||
},
|
||||
...authentication_options,
|
||||
},
|
||||
},
|
||||
execute: async (ctx) => {
|
||||
@@ -74,6 +76,15 @@ export default {
|
||||
throw SHOW_USAGE;
|
||||
}
|
||||
|
||||
if (!options.username !== !options.password) {
|
||||
stderr('Please specify both --username and --password, or neither');
|
||||
return 1;
|
||||
}
|
||||
const authenticator = new Authenticator({
|
||||
username: options.username,
|
||||
password: options.password,
|
||||
});
|
||||
|
||||
const remote_data = determine_fetch_remote(remote, remotes);
|
||||
await git.pull({
|
||||
fs,
|
||||
@@ -87,6 +98,7 @@ export default {
|
||||
fastForward: options['ff'],
|
||||
fastForwardOnly: options['ff-only'],
|
||||
onMessage: (message) => { stdout(message); },
|
||||
...authenticator.get_auth_callbacks(stderr),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user