Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure git commands are run in the appropriate directory to prevent "fatal: Not a git repository (or any parent up to mount point /srv)" #10532

Merged
merged 1 commit into from Sep 26, 2016

Conversation

Projects
None yet
2 participants
@bkbeckman
Copy link
Contributor

commented Sep 20, 2016

Please issue pull request against the 3.x-dev branch as the master branch currently represents our 2.X version which is in LTS mode.

Important fixes will be merged into master if needed after it was merged to 3.x-dev.

@mattab

This comment has been minimized.

Copy link
Member

commented Sep 23, 2016

Hi @bkbeckman

Thanks for the pull request!

Are you using the AWS Toolkit to run Piwik tests?

@mattab mattab added this to the 3.0.0-b1 milestone Sep 23, 2016

@bkbeckman

This comment has been minimized.

Copy link
Contributor Author

commented Sep 23, 2016

No. I was just seeing the error message from #8771 when running console commands with an absolute path.

@mattab

This comment has been minimized.

Copy link
Member

commented Sep 23, 2016

Ok, this console command is not related to the error messages there.

@mattab mattab closed this Sep 23, 2016

@bkbeckman

This comment has been minimized.

Copy link
Contributor Author

commented Sep 26, 2016

From my investigations, it is. The linked error message will be triggered any time the console command is executed with an absolute path inside of a directory that does not contain a .git folder.

Example,

$ ll -a
total 16
drwxr-x---  4 piwikadmin apache 4096 Sep 22 20:11 .
drwxr-xr-x  4 root       root   4096 Sep 22 20:10 ..
drwxrwxr-x 13 piwikadmin apache 4096 Sep 23 16:15 piwik
$ ./piwik/console examplecommand:helloworld
fatal: Not a git repository (or any parent up to mount point /media/ephemeral0)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

Note the error message.

Now let's see what happens when we run the command inside of the piwik directory.

$ ll -a
total 2720
drwxrwxr-x 13 piwikadmin apache    4096 Sep 23 16:15 .
drwxr-x---  4 piwikadmin apache    4096 Sep 22 20:11 ..
drwxrwxr-x  9 piwikadmin apache    4096 Sep 16 17:26 .git
-rw-rw-r--  1 piwikadmin apache     711 Sep  1 15:29 .gitattributes
-rw-rw-r--  1 piwikadmin apache    1319 Sep 16 17:12 .gitignore
-rw-rw-r--  1 piwikadmin apache    4774 Sep 23 18:22 .gitmodules
....more files...

Note the existence of .git. Let's run the command again from this directory and see what we get...

$ ./console examplecommand:helloworld
HelloWorld:

No issues -- confirming this issue is the same one outlined in #8771.

Now, to see why this is happening, we open up Piwik\Plugins\TestRunner\Commands\TestRunOnAws.php and add a new line to the getCurrentGitHash() method.

    private function getCurrentGitHash()
    {
        // we should not use 'git' executable unless we are in a git clone
        if(!SettingsPiwik::isGitDeployment()) {
            return 'WARN: it does not look like a Piwik repository clone - you must setup Piwik from git to proceed';
        }
        debug_print_backtrace();
        return trim(`git rev-parse HEAD`);
    }

Note the debug statement. Now when we run the console command again.

$ ./brian/console examplecommand:helloworld
#0  Piwik\Plugins\TestRunner\Commands\TestsRunOnAws->getCurrentGitHash() called at [/media/ephemeral0/piwikinstalls/brian/plugins/TestRunner/Commands/TestsRunOnAws.php:42]
#1  Piwik\Plugins\TestRunner\Commands\TestsRunOnAws->configure() called at [/media/ephemeral0/piwikinstalls/brian/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:65]
#2  Symfony\Component\Console\Command\Command->__construct() called at [/media/ephemeral0/piwikinstalls/brian/core/Console.php:91]
#3  Piwik\Console->addCommandIfExists(Piwik\Plugins\TestRunner\Commands\TestsRunOnAws) called at [/media/ephemeral0/piwikinstalls/brian/core/Console.php:74]
#4 [....SNIP....]
#5  Symfony\Component\Console\Application->run() called at [/media/ephemeral0/piwikinstalls/brian/console:27]
fatal: Not a git repository (or any parent up to mount point /media/ephemeral0)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
HelloWorld:

We can see that core/Console.php:91 is loading the TestsRunOnAwsclass and that Piwik\Plugins\TestRunner\Commands\TestsRunOnAws:42 is calling the getCurrentGitHashmethod, which is execing a git command on a relative directory, which will throw an error message if the current working directory is not a working git directory.

Thus, I'm quite confident that #8771 is resolved by this pull request.

@mattab

This comment has been minimized.

Copy link
Member

commented Sep 26, 2016

Thanks for additional information.

@mattab mattab reopened this Sep 26, 2016

@mattab mattab merged commit 5248f60 into matomo-org:3.x-dev Sep 26, 2016

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details

@mattab mattab added the Bug label Oct 5, 2016

@mattab mattab changed the title Ensure git commands are run in the appropriate directory. (#8771) Ensure git commands are run in the appropriate directory to prevent "fatal: Not a git repository (or any parent up to mount point /srv)" Oct 5, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.