Skip to content

Commit

Permalink
doc(git): Expand documentation and add FIXMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
AtkinsSJ authored and KernelDeimos committed Jun 28, 2024
1 parent 711dbc0 commit d077504
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/git/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ While this is built for Puter, the only Puter-specific parts are:

By modifying these, and the values in `config/`, you should be able to port it to other environments.

## Libraries

- [**chalk**](https://www.npmjs.com/package/chalk): For more convenient coloring and styling of output.
- [**diff**](https://www.npmjs.com/package/diff): For producing and applying diff patches.
- [**isomorphic-git**](https://isomorphic-git.org): For interacting with the git repository. See section below.

## Subcommand structure

The `git` CLI is structured as a series of sub-commands - `git branch` has nothing in common with `git version`, for example. Each of these is modelled as its own file in `src/subcommands`, and should export a default object with the following structure:
Expand Down Expand Up @@ -79,6 +85,14 @@ The `dir` and `gitdir` variables can then be passed to isomorphic-git methods th
If no repository is found, this will throw an error, which is then printed to stderr.
(isomorphic-git's `git.findRoot()` does not implement checks for a `.git` text file that points to an alternative directory that git's metadata is stored in. We should maybe upstream this.)

### Parallel processing

Filesystem access going over the network has a performance cost, so to try and counteract this, we try to
do things in parallel. There's a lot of use of `await Promise.all(...)` and `await Promise.allSettled()`.
Because isomorphic-git has its own caching, (using the `cache` object,) it's possible that this doesn't
actually help. Once performance becomes an issue, it'd be worth experimenting to see if running the same
commands in sequence is faster, especially where they access the same files.

## Isomorphic-git

The library we use for most interaction with git's files is [isomorphic-git](https://isomorphic-git.org).
Expand Down
2 changes: 2 additions & 0 deletions packages/git/src/subcommands/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export default {
filepaths: pathspecs,
});

// TODO: We should complain if one or more pathspecs don't match anything.

const operations = file_status
.filter(([ filepath, head, worktree, staged ]) => worktree !== staged)
.map(([ filepath, head, worktree, index ]) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/git/src/subcommands/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const BRANCH = {
const { options, positionals, tokens } = args;
const cache = {};

// TODO: This manual processing is done because parseArgs() doesn't allow options to have only a short name.
// Replace it with a better args parsing library.
for (const token of tokens) {
if (token.kind !== 'option') continue;

Expand Down
3 changes: 3 additions & 0 deletions packages/git/src/subcommands/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const CHECKOUT = {
const { options, positionals, tokens } = args;
const cache = {};

// TODO: This manual processing is done because parseArgs() doesn't allow options to have only a short name.
// Replace it with a better args parsing library.
for (const token of tokens) {
if (token.kind !== 'option') continue;

Expand Down Expand Up @@ -124,6 +126,7 @@ const CHECKOUT = {

// Check out a branch or commit
// TODO: Check out files.
// TODO: Checking out a branch name that exists in a remote but not locally, should create a new branch tracking that remote.
{
if (positionals.length === 0 || positionals.length > 1) {
stderr('error: Expected 1 argument, for <branch>.');
Expand Down
3 changes: 3 additions & 0 deletions packages/git/src/subcommands/restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export default {

const { dir, gitdir } = await find_repo_root(fs, env.PWD);

// TODO: We should complain if one or more pathspecs don't match anything.

const operations = await git.walk({
fs, dir, gitdir, cache,
trees: [
Expand All @@ -86,6 +88,7 @@ export default {
return null;
}

// FIXME: Allow restoring ignored files that are tracked
if (await git.isIgnored({ fs, dir, gitdir, filepath }))
return null;

Expand Down

0 comments on commit d077504

Please sign in to comment.