go-git icon indicating copy to clipboard operation
go-git copied to clipboard

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

Open mflendrich opened this issue 6 years ago • 2 comments

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 #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

mflendrich avatar Jul 31 '19 21:07 mflendrich

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

jk2K avatar Feb 06 '20 15:02 jk2K

@jk2K thx for your comment, it really helps.

velp avatar Mar 21 '20 19:03 velp