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

How to get an array of changed files?

Open derUli opened this issue 6 years ago • 3 comments

There is the method hasChanges() which returns true, if there are any changed files. But I don't see a method which returns what files have been changed. Am I overlooking something?

derUli avatar Mar 10 '19 13:03 derUli

Hello, you are right, there is no method which returns what files have been changed. Can you send PR?

janpecha avatar Mar 15 '19 07:03 janpecha

Yes. I think about the implementation details. We get filenames and a letter determine the type of status for any file (new file, modified file, deleted file) from git status command line. example given "M myfile.php" would mean, the already added file myfile.php was changed.

So it makes sense to make getChanges() to return an associative array of filename => Type of status. Additionally we should have constants for the file status type GIT_FILE_STATUS_NEW GIT_FILE_STATUS_CHANGED GIT_FILE_STATUS_DELETED

Do you confirm with that?

derUli avatar Mar 15 '19 09:03 derUli

I implemented a getChanges Method.

https://github.com/czproject/git-php/pull/42

Unfortunately i wasn't able to get the tests running on my Windoze machine. But I verified it's function with a simple php script. Which just calls getChanges() on a repository and shows the output. You have to extend your tests by yourself.

C:\Users\deruli\Documents\GitHub\git-php>php test.php
array(1) {
  ["src/GitRepository.php"]=>
  string(1) "M"
}

derUli avatar Mar 15 '19 15:03 derUli