Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenvukhang committed Jul 5, 2023
2 parents f8d4087 + 1b9c89b commit e1c3653
Show file tree
Hide file tree
Showing 23 changed files with 959 additions and 877 deletions.
91 changes: 91 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Contributing to Gitnu

## Main logic flow

1. **Preprocessing** (fallible)
1. Get the path to the [git directory](#git-dir) relative to the
current directory.
2. Get [git aliases][git-aliases].
3. Read the [cache file](#gitnu-cache-file).
2. **Parsing** (infallible)
1. Pass the CLI arguments through a function to obtain a final list
of arguments to actually run.
2. This is where numbers and number-ranges are converted to
pathspecs, depending on the [cache](#gitnu-cache-file).
3. **Running** (fallible)
1. Once the arguments are parsed, all that's left is to run them.
2. If git's sub-command is `status`, then print and parse the
output to build the next cache.

### Error handling

1. if **Preprocessing** fails:
Pass the raw CLI arguments into a `git` command and run that and
use the same exit code.
2. if **Running** fails:
Non-issue. Failing here means there was probably something wrong
with the user-supplied command.

### Non-trivial behavior

#### How does `git nu` manage to call `git-nu`

Based on git's [source code][git-source], in the function
`execv_dashed_external`, any executable that is in `$PATH` that is
named `git-foo-bar` can be ran with `git foo-bar`.

Additionally, flags placed after `git` and before `foo-bar` will be
seen by `git` but not by `git-foo-bar`.

#### Parsing arguments after `git` and before `nu`

Amazingly, this is not necessary as `git` will handle all flags in
this range.

For example, the `-C` flag will make git run from a different
directory, and that will be accounted for by `git`, and not `git-nu`.

Same with configurations set with the `-c` flag.

So running this command from `/foo`

```
> git -C /bar -c alias.zoom=ls-files nu zoom
```

Will actually run `git ls-files` on the repo located at `/bar`.

The caveat is that in code, `git-nu` sees `zoom` as the only argument
(apart from the binary path), and will effectively return `git zoom`.

Setting the directory (from `-C`) and aliasing `zoom` to `ls-files`
(from `-c`) are managed by `git`.

## Glossary

#### `git-dir`

This is the directory where the `HEAD` file is stored. On a normal
clone, it is at `.git/HEAD`, and in bare repositories it's in
`.git/worktrees/<worktree name>/HEAD`. So depending on the state of
the repo, the value of `git-dir` may be one of the following:

- `.git`
- `.git/worktrees/<worktree name>`

`git-dir` can be found by running the command `git rev-parse
--git-dir` from anywhere in the git workspace.

#### Gitnu cache file

Stored in the [git directory](#git-dir). It stores the output of the
last run of `git status` in that workspace.

The first line is the working directory from which `git status` was
ran.

The remaining lines are the ordered pathspecs of that run of `git
status`.

[git-aliases]: https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases
[git-source]: https://github.com/git/git/blob/master/git.c
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gitnu"
version = "0.6.9"
version = "0.7.0-alpha3"
authors = ["Nguyen Vu Khang <[email protected]>"]
description = """
gitnu indexes your git status so you can use numbers instead of filenames.
Expand All @@ -20,9 +20,9 @@ atty = "0.2.14"
[[bin]]
bench = false
test = false
path = "core/main.rs"
path = "src/main.rs"
name = "git-nu"

[lib]
path = "core/lib.rs"
doctest = false
test = false
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Nguyen Vu Khang
Copyright (c) 2023 Nguyen Vu Khang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ GITNU_RELEASE_BIN=$(PWD)/target/release/git-nu
GITNU_DEBUG_BIN=$(PWD)/target/debug/git-nu

PY_UTILS := python3 scripts/utils.py
ONE_TEST := tests::exit_codes
ONE_TEST := 'tests::renames'

current:
make test
Expand Down Expand Up @@ -39,8 +39,8 @@ load-bin:
# MARK: - CI

ci-git-user:
git config --global user.name gitnu-ci
git config --global user.email ci@gitnu.com
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'

py:
@$(PY_UTILS) $(ARG)
Expand Down
141 changes: 0 additions & 141 deletions core/command.rs

This file was deleted.

62 changes: 0 additions & 62 deletions core/git.rs

This file was deleted.

Loading

0 comments on commit e1c3653

Please sign in to comment.