Skip to content

Unexpect behavior when adding dot slash files to working tree #1150

@kurczynski

Description

@kurczynski

When using git in a shell to add a file to the working tree, the same file can be added in different ways. One way it can be added is by adding the bare filename:

$ git add my-file
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   my-file

Another way it can be added is by prefixing the filename with dot slash:

$ git add ./my-file
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   my-file

These both produce the same staged file to be added to the working tree.

However, when adding a file to the working tree using go-git, the same file is stored with a different value in the git index. For example, adding the bare filename:

gitRepo, _ := git.PlainOpen("my-repo")
gitWorktree, _ := gitRepo.Worktree()
gitWorktree.Add("my-file")

Produces the expected staged file in the working tree:

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   my-file

But if the file is added with the prefixed dot slash:

gitRepo, _ := git.PlainOpen("my-repo")
gitWorktree, _ := gitRepo.Worktree()
gitWorktree.Add("./my-file")

A different file is staged:

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   ./my-file

I thought that it might have something to do with the shell expanding the dot slash but that doesn't seem to be the case since I tried adding the dot slash prefixed file using single quotes (git add './my-file') and got the same result.

To me, this is unexpected behavior with git. Is that indeed the case or am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy