0

I need to commit all workdir, but I can't find any solution that can adds the subdirectories to the index. I've tried with git_index_add_bypath() but it's seems to not add the tree for the subdirectories. I'm using Qt and the libgit2 for c, because the language binding for Qt seems to not work.

Irvin Dominin
  • 30,819
  • 9
  • 77
  • 111
pacix
  • 3
  • 1

1 Answers1

2

There are different ways depending on what you need. "commit all workdir" doesn't convey which one.

If you want to update the version of every file that is tracked, you can loop over the entries in the index and call git_index_add_bypath for each.

For anything else, things get murky, as you may or may not want to take ignore rules into account. The general solution would be to use the status API to see which files have been changed or added and add those to the index according to the result you're looking for (ignore rules, adding new files or not, removing files that aren't in the worktree anymore).

Carlos Martín Nieto
  • 5,207
  • 1
  • 15
  • 16
  • Thanks for the answer. I just need to make a function that I can call when a file in the working directory is added or modified. The function has to adds all the new files in the index and commit the changes.With git_index_by_path() i can update the repo for all the files in the working dir but, i can't for the files in the subdirectories that aren't added to the indextree. For the status API i can't find any example for start. Thanks. – pacix Jun 06 '13 at 14:28
  • Take a look at the API and the tests, which make use of those functions. I don't get what you're saying about adding files in dirs, as that works and is no different from adding any other file at any other level. – Carlos Martín Nieto Jun 06 '13 at 19:23
  • Thanks for the help. I've solved with git_index_add_bypath(). The real issue was that the git status command show me the files like they are deleted instead of added. Now after the git_commit_create_v() I call a git_reset with the last commit for target and all works fine. Thanks for your time. – pacix Jun 07 '13 at 09:58