kbjr/Git.php

$repo->add adds all the files of the repository

Closed this issue · 8 comments

zeel commented

I want to add only one file for my commit not any other.
but when I do as following
$repo = Git::open($path_to_repository);
$repo->add($file_to_add);
$repo->commit($msg);

it added all the modified files to that commit.

kbjr commented

Can't confirm this at the moment as I'm out, but the commit method adds the -av flags automatically, which would add all files. Try using ->run('commit ...')

zeel commented

hi,
$repo = Git::open($path_to_repository);
$repo->run("commit $file_to_add");

it hangs

i tried this

$repo = Git::open($path_to_repository);
$repo->run("add $file_to_add");
$repo->commit($msg);

it added all the files.

can you specify what to do specifically?

$repo->run("add $file_to_add"); should be $repo->run("add {$file_to_add}");. See if that helps.

zeel commented

nothing is working. every time all things are being added.

kbjr commented

Okay, let's first determine that the problem is with the library. Run this:

// First, let's be sure what this is
var_dump($file_to_add);

// Make sure that the files aren't already added before we even start
echo $repo->status();

// This should add only the given file
$repo->run('add '.$file_to_add);

// And actually commit the changeset
$repo->run('commit -m "your message"');
zeel commented

Hi,
thanks it worked. thanks for reply :)

kbjr commented

It was probably the commit call, like I thought. You can do it this way for now, but I'm going to add an option to the commit method to avoid this in the future.

kbjr commented

Okay, if you use the latest version @ 49aff09 you can pass in a second parameter to commit to avoid the add all flag:

$repo->add($file_to_add);
$repo->commit('commit message here', false);