+ /**
+ * Returns a list of tracked files in a Git work tree differing from the master branch.
+ * @param string $path Path to the repository
+ * @return array Resulting list of changed files
+ */
+ private function getGitModifiedFiles( $path ) {
+ global $wgMaxShellMemory;
+
+ if ( !is_dir( "$path/.git" ) ) {
+ $this->error( "Error: Not a Git repository!\n", true );
+ }
+
+ // git diff eats memory.
+ $oldMaxShellMemory = $wgMaxShellMemory;
+ if ( $wgMaxShellMemory < 1024000 ) {
+ $wgMaxShellMemory = 1024000;
+ }
+
+ $ePath = wfEscapeShellArg( $path );
+
+ // Find an ancestor in common with master (rather than just using its HEAD)
+ // to prevent files only modified there from showing up in the list.
+ $cmd = "cd $ePath && git merge-base master HEAD";
+ $retval = 0;
+ $output = wfShellExec( $cmd, $retval );
+ if ( $retval !== 0 ) {
+ $this->error( "Error retrieving base SHA1 from Git!\n", true );
+ }
+
+ // Find files in the working tree that changed since then.
+ $eBase = wfEscapeShellArg( rtrim( $output, "\n" ) );
+ $cmd = "cd $ePath && git diff --name-only --diff-filter AM $eBase";
+ $retval = 0;
+ $output = wfShellExec( $cmd, $retval );
+ if ( $retval !== 0 ) {
+ $this->error( "Error retrieving list from Git!\n", true );
+ }
+
+ $wgMaxShellMemory = $oldMaxShellMemory;
+
+ $arr = [];
+ $filename = strtok( $output, "\n" );
+ while ( $filename !== false ) {
+ if ( $filename !== '' ) {
+ $arr[] = "$path/$filename";
+ }
+ $filename = strtok( "\n" );
+ }
+
+ return $arr;
+ }
+