Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

AddGlob("*") adds .git to the index #1201

Open
mflendrich opened this issue Jul 31, 2019 · 2 comments
Open

AddGlob("*") adds .git to the index #1201

mflendrich opened this issue Jul 31, 2019 · 2 comments

Comments

@mflendrich
Copy link

This bug looks similar to #814 but affects AddGlob rather than Add.

Reproduction Steps

  1. Execute this code
  repo, err := git.PlainInit("/some/dir", false)
  if err != nil {
    return errors.Wrap(err, "git init")
  }

  // (put files in /some/dir)

  wt, err := repo.Worktree()
  if err != nil {
    return errors.Wrap(err, "worktree")
  }

  if err := wt.AddGlob("*"); err != nil {
    return errors.Wrap(err, "AddGlob")
  }

  co := git.CommitOptions{
    Author: &object.Signature{
      Name:  "somebody",
      Email: "[email protected]",
      When:  time.Now(),
    },  
  }
  if _, err := wt.Commit("initial commit", &co); err != nil {
    return errors.Wrap(err, "initial commit")
  }
  1. Observe that .git has been committed
$ git -C /some/dir rev-list --objects --all
f99c70ad6ad44782839e9248dcc6cdb8270d6bb5                                                       
4756d7c1a705171a7b08424975a952d69382753f                                                    
f73163ae5843aa96729746da9fdd072cdb9ee683                                                     
b81cb5bdf00b207ae19bb4a7276723ac90597d02 .git                                                        
cb089cd89a3d7686d284d8761201649346b5aa1c .git/HEAD                                                       
24d50854b1bbfdba94e035b02c4f4b6589878e3b .git/objects                                                    
75c0fa091470ab437664f51c46b34bffafccfd1d .git/objects/84                                                
d20258d48fcfcd0a06eb242a150d96a94cac9646 .git/objects/84/4a084e76baea8fe3fb79b8789f685f09d63f6c                     
e30b22d468a87a57704f522b698df0c60ab819bb .git/objects/cb                                               
ed4e0ce2940e218f40461b8fe76e8e37040a39b2 .git/objects/cb/089cd89a7d7686d284d8761251649346b5aa1c         
d7806218c87724c0ac16f1895b3eeab751c6e96c legit-file1.txt                                                    
d729657ed22be0a69b49765ba6db262850723a97 legit-file2.txt

Expected behavior

Either of:

  • AddGlob("*") does not add the contents of /.git to the index (IIUC that means being equivalent to Add(".") after Fix for "Worktree Add function adds ".git" directory" #815)
  • AddGlob("*") adds the contents of /.git to the index, but the documentation says that (and
    recommends a way to achieve the equivalent of git add -A)

Actual behavior

  • AddGlob("*") adds the contents of /.git to the index
@jk2K
Copy link

jk2K commented Feb 6, 2020

you can use AddGlob(".") instead of AddGLob("*"), AddGLob(".") will not add .git

@velp
Copy link

velp commented Mar 21, 2020

@jk2K thx for your comment, it really helps.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants