mirror of
https://github.com/HeyPuter/puter.git
synced 2025-02-02 23:28:39 +08:00
refactor(git): Use dir/gitdir variable names like isogit does
I prefer the other names, but being able to type `{ dir, gitdir }` is shorter and a lot less error-prone than `{ dir: repository_dir, gitdir: git_dir }`.
This commit is contained in:
parent
35e4453930
commit
1822ace296
@ -26,7 +26,7 @@ export const PROXY_URL = 'https://cors.isomorphic-git.org';
|
||||
* @throws Error If no git repository could be found, or another error occurred.
|
||||
* @param fs Filesystem API
|
||||
* @param pwd Directory to search from
|
||||
* @returns {Promise<{repository_dir: (string|*), git_dir: (string|string)}>}
|
||||
* @returns {Promise<{dir: (string|*), gitdir: (string|string)}>} dir and gitdir are the same as in git.foo({dir, gitdir}) APIs.
|
||||
*/
|
||||
export const find_repo_root = async (fs, pwd) => {
|
||||
if (!path.isAbsolute(pwd))
|
||||
@ -54,8 +54,8 @@ export const find_repo_root = async (fs, pwd) => {
|
||||
// TODO: The git cli seems to check other things, maybe try to match that behaviour.
|
||||
|
||||
const result = {
|
||||
repository_dir: current_path,
|
||||
git_dir: current_git_path,
|
||||
dir: current_path,
|
||||
gitdir: current_git_path,
|
||||
};
|
||||
|
||||
// Non-default-git-folder repos have .git as a text file containing the git dir path.
|
||||
@ -65,7 +65,7 @@ export const find_repo_root = async (fs, pwd) => {
|
||||
const prefix = 'gitdir:';
|
||||
if (!contents.startsWith(prefix))
|
||||
throw new Error(`invalid gitfile format: ${current_git_path}`);
|
||||
result.git_dir = contents.slice(prefix.length).trim();
|
||||
result.gitdir = contents.slice(prefix.length).trim();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -39,12 +39,12 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
const { repository_dir, git_dir } = await find_repo_root(fs, env.PWD);
|
||||
const { dir, gitdir } = await find_repo_root(fs, env.PWD);
|
||||
|
||||
await git.add({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
ignored: false,
|
||||
filepath: pathspecs,
|
||||
parallel: true,
|
||||
|
@ -108,18 +108,18 @@ const BRANCH = {
|
||||
}
|
||||
}
|
||||
|
||||
const { repository_dir, git_dir } = await find_repo_root(fs, env.PWD);
|
||||
const { dir, gitdir } = await find_repo_root(fs, env.PWD);
|
||||
|
||||
const get_current_branch = async () => git.currentBranch({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
test: true,
|
||||
});
|
||||
const get_all_branches = async () => git.listBranches({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
});
|
||||
const get_branch_data = async () => {
|
||||
const [branches, current_branch] = await Promise.all([
|
||||
@ -149,8 +149,8 @@ const BRANCH = {
|
||||
|
||||
await git.branch({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
ref: new_name,
|
||||
object: old_name,
|
||||
checkout: false,
|
||||
@ -176,14 +176,14 @@ const BRANCH = {
|
||||
throw new Error(`Branch '${branch}' not found.`);
|
||||
const oid = await git.resolveRef({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
ref: branch,
|
||||
});
|
||||
const result = await git.deleteBranch({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
ref: branch,
|
||||
});
|
||||
return oid;
|
||||
@ -227,16 +227,16 @@ const BRANCH = {
|
||||
throw new Error(`A branch named '${new_name}' already exists.`);
|
||||
await git.deleteBranch({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
ref: new_name,
|
||||
});
|
||||
}
|
||||
|
||||
await git.renameBranch({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
ref: new_name,
|
||||
oldref: old_name,
|
||||
checkout: old_name === current_branch,
|
||||
@ -285,8 +285,8 @@ const BRANCH = {
|
||||
|
||||
await git.branch({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
ref: branch_name,
|
||||
object: starting_point,
|
||||
checkout: false,
|
||||
|
@ -75,19 +75,19 @@ const CHECKOUT = {
|
||||
}
|
||||
}
|
||||
|
||||
const { repository_dir, git_dir } = await find_repo_root(fs, env.PWD);
|
||||
const { dir, gitdir } = await find_repo_root(fs, env.PWD);
|
||||
|
||||
// DRY: Copied from branch.js
|
||||
const get_current_branch = async () => git.currentBranch({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
test: true,
|
||||
});
|
||||
const get_all_branches = async () => git.listBranches({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
});
|
||||
const get_branch_data = async () => {
|
||||
const [branches, current_branch] = await Promise.all([
|
||||
@ -111,8 +111,8 @@ const CHECKOUT = {
|
||||
|
||||
await git.branch({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
ref: branch_name,
|
||||
object: starting_point,
|
||||
checkout: true,
|
||||
@ -142,8 +142,8 @@ const CHECKOUT = {
|
||||
|
||||
await git.checkout({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
cache,
|
||||
ref: branch_name,
|
||||
force: options.force,
|
||||
|
@ -49,7 +49,7 @@ export default {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const { repository_dir, git_dir } = await find_repo_root(fs, env.PWD);
|
||||
const { dir, gitdir } = await find_repo_root(fs, env.PWD);
|
||||
|
||||
let user_name;
|
||||
let user_email;
|
||||
@ -64,14 +64,14 @@ export default {
|
||||
} else {
|
||||
user_name = await git.getConfig({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
path: 'user.name',
|
||||
});
|
||||
user_email = await git.getConfig({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
path: 'user.email',
|
||||
});
|
||||
}
|
||||
@ -82,8 +82,8 @@ export default {
|
||||
|
||||
const commit_hash = await git.commit({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
message: options.message,
|
||||
author: {
|
||||
name: user_name,
|
||||
@ -93,8 +93,8 @@ export default {
|
||||
|
||||
const branch = await git.currentBranch({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
});
|
||||
const commit_title = options.message.split('\n')[0];
|
||||
const short_hash = shorten_hash(commit_hash);
|
||||
|
@ -46,15 +46,15 @@ export default {
|
||||
const key = positionals.shift();
|
||||
const value = positionals.shift();
|
||||
|
||||
const { repository_dir, git_dir } = await find_repo_root(fs, env.PWD);
|
||||
const { dir, gitdir } = await find_repo_root(fs, env.PWD);
|
||||
|
||||
if (value || options.unset) {
|
||||
// Set it
|
||||
// TODO: If --unset AND we have a value, we should only remove an entry that has that value
|
||||
await git.setConfig({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
path: key,
|
||||
value: options.unset ? undefined : value,
|
||||
});
|
||||
@ -64,8 +64,8 @@ export default {
|
||||
// Get it
|
||||
const result = await git.getConfig({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
path: key,
|
||||
});
|
||||
if (result === undefined) {
|
||||
|
@ -44,14 +44,14 @@ export default {
|
||||
const { options, positionals } = args;
|
||||
const cache = {};
|
||||
|
||||
const { repository_dir, git_dir } = await find_repo_root(fs, env.PWD);
|
||||
const { dir, gitdir } = await find_repo_root(fs, env.PWD);
|
||||
|
||||
// TODO: Support <refspec> syntax.
|
||||
|
||||
const remotes = await git.listRemotes({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
});
|
||||
|
||||
if (options.all) {
|
||||
@ -62,8 +62,8 @@ export default {
|
||||
http,
|
||||
cache,
|
||||
corsProxy: PROXY_URL,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
remote,
|
||||
onMessage: (message) => { stdout(message); },
|
||||
});
|
||||
@ -79,8 +79,8 @@ export default {
|
||||
http,
|
||||
cache,
|
||||
corsProxy: PROXY_URL,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
...remote_data,
|
||||
onMessage: (message) => { stdout(message); },
|
||||
});
|
||||
|
@ -48,12 +48,12 @@ export default {
|
||||
|
||||
const depth = Number(options['max-count']) || undefined;
|
||||
|
||||
const { repository_dir, git_dir } = await find_repo_root(fs, env.PWD);
|
||||
const { dir, gitdir } = await find_repo_root(fs, env.PWD);
|
||||
|
||||
const log = await git.log({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
depth,
|
||||
});
|
||||
|
||||
|
@ -40,7 +40,7 @@ export default {
|
||||
const { stdout, stderr } = io;
|
||||
const { options, positionals, tokens } = args;
|
||||
|
||||
const { repository_dir, git_dir } = await find_repo_root(fs, env.PWD);
|
||||
const { dir, gitdir } = await find_repo_root(fs, env.PWD);
|
||||
|
||||
// TODO: Other subcommands:
|
||||
// - set-head
|
||||
@ -56,8 +56,8 @@ export default {
|
||||
// No subcommand, so list remotes
|
||||
const remotes = await git.listRemotes({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
});
|
||||
for (const remote of remotes) {
|
||||
if (options.verbose) {
|
||||
@ -79,8 +79,8 @@ export default {
|
||||
const [ name, url ] = positionals;
|
||||
await git.addRemote({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
remote: name,
|
||||
url: url,
|
||||
});
|
||||
@ -98,8 +98,8 @@ export default {
|
||||
// First, check if the remote exists so we can show an error if it doesn't.
|
||||
const remotes = await git.listRemotes({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
});
|
||||
if (!remotes.find(it => it.remote === name)) {
|
||||
stderr(`error: No such remote: '${name}'`);
|
||||
@ -108,8 +108,8 @@ export default {
|
||||
|
||||
await git.deleteRemote({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
remote: name,
|
||||
});
|
||||
return;
|
||||
|
@ -37,7 +37,7 @@ export default {
|
||||
|
||||
process_commit_formatting_options(options);
|
||||
|
||||
const { repository_dir, git_dir } = await find_repo_root(fs, env.PWD);
|
||||
const { dir, gitdir } = await find_repo_root(fs, env.PWD);
|
||||
|
||||
const objects = [...positionals];
|
||||
|
||||
@ -58,8 +58,8 @@ export default {
|
||||
// That may also be a tag, so we recurse.
|
||||
const target = await git.readObject({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
oid: tag.object,
|
||||
format: 'parsed',
|
||||
cache,
|
||||
@ -74,16 +74,16 @@ export default {
|
||||
// Could be any ref, so first get the oid that's referred to.
|
||||
const oid = await git.resolveRef({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
ref,
|
||||
});
|
||||
|
||||
// Then obtain the object and parse it.
|
||||
const parsed_object = await git.readObject({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
oid,
|
||||
format: 'parsed',
|
||||
cache,
|
||||
|
@ -34,13 +34,13 @@ export default {
|
||||
const { stdout, stderr } = io;
|
||||
const { options, positionals } = args;
|
||||
|
||||
const { repository_dir, git_dir } = await find_repo_root(fs, env.PWD);
|
||||
const { dir, gitdir } = await find_repo_root(fs, env.PWD);
|
||||
|
||||
// Gather up file differences
|
||||
const file_status = await git.statusMatrix({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
ignored: false,
|
||||
});
|
||||
|
||||
@ -53,7 +53,7 @@ export default {
|
||||
const STAGE = 3;
|
||||
|
||||
for (const file of file_status) {
|
||||
const absolute_path = path.resolve(repository_dir, file[0]);
|
||||
const absolute_path = path.resolve(dir, file[0]);
|
||||
const relative_path = path.relative(env.PWD, absolute_path);
|
||||
|
||||
const status_string = `${file[1]}${file[2]}${file[3]}`;
|
||||
@ -104,8 +104,8 @@ export default {
|
||||
|
||||
const current_branch = await git.currentBranch({
|
||||
fs,
|
||||
dir: repository_dir,
|
||||
gitdir: git_dir,
|
||||
dir,
|
||||
gitdir,
|
||||
});
|
||||
stdout(`On branch ${current_branch}\n`);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user