Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gix status does not show newly staged files before the first commit #1770

Closed
EliahKagan opened this issue Jan 15, 2025 · 1 comment · Fixed by #1772
Closed

gix status does not show newly staged files before the first commit #1770

EliahKagan opened this issue Jan 15, 2025 · 1 comment · Fixed by #1772
Assignees

Comments

@EliahKagan
Copy link
Member

EliahKagan commented Jan 15, 2025

Current behavior 😯

Since 84019cb (#1769), gix status works in repositories that have not yet had their first commit. Rather than reporting an error, it shows the status of each file that has unstaged changes. This includes:

  • Files in the ? state that have been created but are not in the index.
  • Files in the M state that are in the index but have different contents on disk.

However, it does not show:

  • Files in the A state that are in the index and the same on disk.

In contrast, those are shown when the repository has been born, i.e., when there is an actual HEAD commit.

Expected behavior 🤔

Staged but not committed changes should be shown in the output of gix status. Since gix status now supports being run before the first commit, this should be the case then, too, where every file in the index is uncommitted.

These files should be shown in the A state, unless there is a reason to depart from the way Git presents them.

Git behavior

Git shows these files in the A state:

ek in 🌐 catenary in ~/src
❯ git init repo
Initialized empty Git repository in /home/ek/src/repo/.git/

ek in 🌐 catenary in ~/src
❯ cd repo

ek in 🌐 catenary in repo on  main
❯ echo old >file

ek in 🌐 catenary in repo on  main [?]
❯ git add .

ek in 🌐 catenary in repo on  main [+]
❯ git status
On branch main

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
 new file:   file


ek in 🌐 catenary in repo on  main [+]
❯ git status --short
A  file

(The file contents "old" are used to avoid deviating from the procedure shown below to produce the bug in gitoxide. But since further steps are only needed to verify that the bug in gitoxide does not extend further, they are omitted in the run with Git shown above, which is why the above terminal log has no "new".)

Steps to reproduce 🕹

Build gitoxide after 84019cb (#1769) and replace ~/repos/gitoxide/target/debug/gix with the path to the built gix executable, if different, in the following. This tests more than the specific situation that has the bug, in order to show specifically when the bug does and does not occur:

git init repo
cd repo
echo old >file
~/repos/gitoxide/target/debug/gix status  # The file should be listed in the ? state and it is.
git add file
~/repos/gitoxide/target/debug/gix status  # The file should be listed in the A state but it is not listed at all (this is the bug).
echo new >file
~/repos/gitoxide/target/debug/gix status  # The file should be listed in the M state and it is.
git add file
~/repos/gitoxide/target/debug/gix status  # Verify before we commit that the bug is still observable.
git commit -m 'Initial commit'
~/repos/gitoxide/target/debug/gix status  # The file should not be shown, is not.
touch other-file
~/repos/gitoxide/target/debug/gix status  # The other file should be listed in the ? state and it is.
git add other-file
~/repos/gitoxide/target/debug/gix status  # The other file should be listed in the A state and it is.

Here's a full transcript of a run of that, on an Arch Linux system:

ek in 🌐 catenary in ~/src
❯ git init repo
Initialized empty Git repository in /home/ek/src/repo/.git/

ek in 🌐 catenary in ~/src
❯ cd repo

ek in 🌐 catenary in repo on  main
❯ echo old >file

ek in 🌐 catenary in repo on  main [?]
❯ ~/repos/gitoxide/target/debug/gix status  # The file should be listed in the ? state and it is.
 15:22:25 status done 0.0 files in 0.00s (0.0 files/s)
  ? file

ek in 🌐 catenary in repo on  main [?]
❯ git add file

ek in 🌐 catenary in repo on  main [+]
❯ ~/repos/gitoxide/target/debug/gix status  # The file should be listed in the A state but it is not listed at all (this is the bug).
 15:22:36 status done 1.0 files in 0.00s (808.0 files/s)

ek in 🌐 catenary in repo on  main [+]
❯ echo new >file

ek in 🌐 catenary in repo on  main [!+]
❯ ~/repos/gitoxide/target/debug/gix status  # The file should be listed in the M state and it is.
 15:22:47 status done 1.0 files in 0.00s (684.0 files/s)
  M file

ek in 🌐 catenary in repo on  main [!+]
❯ git add file

ek in 🌐 catenary in repo on  main [+]
❯ ~/repos/gitoxide/target/debug/gix status  # Verify before we commit that the bug is still observable.
 15:22:56 status done 1.0 files in 0.00s (800.0 files/s)

ek in 🌐 catenary in repo on  main [+]
❯ git commit -m 'Initial commit'
[main (root-commit) e6b257f] Initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 file

ek in 🌐 catenary in repo on  main
❯ ~/repos/gitoxide/target/debug/gix status  # The file should not be shown, is not.
 15:23:09 status done 1.0 files in 0.00s (614.0 files/s)

ek in 🌐 catenary in repo on  main
❯ touch other-file

ek in 🌐 catenary in repo on  main [?]
❯ ~/repos/gitoxide/target/debug/gix status  # The other file should be listed in the ? state and it is.
 15:23:18 status done 1.0 files in 0.00s (674.0 files/s)
  ? other-file

ek in 🌐 catenary in repo on  main [?]
❯ git add other-file

ek in 🌐 catenary in repo on  main [+]
❯ ~/repos/gitoxide/target/debug/gix status  # The other file should be listed in the A state and it is.
 15:23:27 status done 2.0 files in 0.00s (1.4K files/s)
 A  other-file
@Byron Byron self-assigned this Jan 16, 2025
@Byron
Copy link
Member

Byron commented Jan 16, 2025

Thanks a lot for reporting!

I can reproduce the issue and am working on the fix right now.

Byron added a commit that referenced this issue Jan 16, 2025
…born repository. (#1770)

Previously it wouldn't show them.
Byron added a commit that referenced this issue Jan 16, 2025
…born repository. (#1770)

Previously it wouldn't show them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants