mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
feat(git): Add start-revision and file arguments to git log
This commit is contained in:
parent
eb2b6a08b0
commit
49c2f16351
@ -17,7 +17,6 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import path from 'path-browserify';
|
import path from 'path-browserify';
|
||||||
import git from 'isomorphic-git';
|
|
||||||
|
|
||||||
export const PROXY_URL = 'https://cors.isomorphic-git.org';
|
export const PROXY_URL = 'https://cors.isomorphic-git.org';
|
||||||
|
|
||||||
@ -110,3 +109,33 @@ export const determine_fetch_remote = (remote_name_or_url, remotes) => {
|
|||||||
throw new Error(`'${remote_name_or_url}' does not appear to be a git repository`);
|
throw new Error(`'${remote_name_or_url}' does not appear to be a git repository`);
|
||||||
return remote_data;
|
return remote_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Divide up the positional arguments into those before the `--` separator, and those after it.
|
||||||
|
* @param arg_tokens Tokens array from parseArgs({ tokens: true })
|
||||||
|
* @returns {{before: string[], after: string[]}}
|
||||||
|
*/
|
||||||
|
export const group_positional_arguments = (arg_tokens) => {
|
||||||
|
let saw_separator = false;
|
||||||
|
const result = {
|
||||||
|
before: [],
|
||||||
|
after: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const token of arg_tokens) {
|
||||||
|
if (token.kind === 'option-terminator') {
|
||||||
|
saw_separator = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (token.kind === 'positional') {
|
||||||
|
if (saw_separator) {
|
||||||
|
result.after.push(token.value);
|
||||||
|
} else {
|
||||||
|
result.before.push(token.value);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@ -17,15 +17,17 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import git from 'isomorphic-git';
|
import git from 'isomorphic-git';
|
||||||
import { find_repo_root } from '../git-helpers.js';
|
import { find_repo_root, group_positional_arguments } from '../git-helpers.js';
|
||||||
import { commit_formatting_options, format_commit, process_commit_formatting_options } from '../format.js';
|
import { commit_formatting_options, format_commit, process_commit_formatting_options } from '../format.js';
|
||||||
|
import { SHOW_USAGE } from '../help.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'log',
|
name: 'log',
|
||||||
usage: 'git log [<formatting-option>...] [--max-count <n>] <revision>',
|
usage: 'git log [<formatting-option>...] [--max-count <n>] [<revision>] [[--] <path>]',
|
||||||
description: 'Show commit logs, starting at the given revision.',
|
description: 'Show commit logs, starting at the given revision.',
|
||||||
args: {
|
args: {
|
||||||
allowPositionals: false,
|
allowPositionals: true,
|
||||||
|
tokens: true,
|
||||||
options: {
|
options: {
|
||||||
...commit_formatting_options,
|
...commit_formatting_options,
|
||||||
'max-count': {
|
'max-count': {
|
||||||
@ -38,23 +40,27 @@ export default {
|
|||||||
execute: async (ctx) => {
|
execute: async (ctx) => {
|
||||||
const { io, fs, env, args } = ctx;
|
const { io, fs, env, args } = ctx;
|
||||||
const { stdout, stderr } = io;
|
const { stdout, stderr } = io;
|
||||||
const { options, positionals } = args;
|
const { options, positionals, tokens } = args;
|
||||||
|
|
||||||
process_commit_formatting_options(options);
|
process_commit_formatting_options(options);
|
||||||
|
|
||||||
// TODO: Log of a specific file
|
|
||||||
// TODO: Log of a specific branch
|
|
||||||
// TODO: Log of a specific commit
|
|
||||||
|
|
||||||
const depth = Number(options['max-count']) || undefined;
|
const depth = Number(options['max-count']) || undefined;
|
||||||
|
|
||||||
const { dir, gitdir } = await find_repo_root(fs, env.PWD);
|
const { dir, gitdir } = await find_repo_root(fs, env.PWD);
|
||||||
|
|
||||||
|
const { before: refs, after: paths } = group_positional_arguments(tokens);
|
||||||
|
if (refs.length > 1 || paths.length > 1) {
|
||||||
|
stderr('error: Too many revisions or paths given. Expected [<revision>] [[--] <path>]');
|
||||||
|
throw SHOW_USAGE;
|
||||||
|
}
|
||||||
|
|
||||||
const log = await git.log({
|
const log = await git.log({
|
||||||
fs,
|
fs,
|
||||||
dir,
|
dir,
|
||||||
gitdir,
|
gitdir,
|
||||||
depth,
|
depth,
|
||||||
|
ref: refs[0],
|
||||||
|
filepath: paths[0],
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const commit of log) {
|
for (const commit of log) {
|
||||||
|
Loading…
Reference in New Issue
Block a user