Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Call to undefined method CzProject\GitPhp\Git::fetch() #93

Answered by janpecha
Lexian-droid asked this question in Q&A
Discussion options

Hello, I'm experimenting with this tool and I'm kind of having problems, I'm unable to figure out why, but I'm unable to do a Git::Fetch() in my codebase. I am running Laravel 10, Php 8.1, and I have the latest version of CzProject\GitPhp.

The error is

 Error
 Call to undefined method CzProject\GitPhp\Git::fetch()
 at app\Console\Commands\utility_update_packages.php:40
 36▕ foreach ($repositories as $repository) {
 37▕ // Create a new GitPhp instance
 38▕
 39▕ // Fetch the repository
 ➜ 40▕ $git->fetch();
 41▕
 42▕ // echo it out
 43▕ echo "Updated " . $repository->name . "\n";
 44▕ }
 1 vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:36
 App\Console\Commands\utility_update_packages::handle()
 2 vendor\laravel\framework\src\Illuminate\Container\Util.php:41
 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()

and the code is:

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\repository;
use CzProject\GitPhp\Git;
class utility_update_packages extends Command
{
 /**
 * The name and signature of the console command.
 *
 * @var string
 */
 protected $signature = 'swu:update_packages';
 /**
 * The console command description.
 *
 * @var string
 */
 protected $description = '';
 /**
 * Execute the console command.
 */
 public function handle()
 {
 $git = new Git;
 // Collect Repositories
 $repositories = repository::all();
 // Fetch each repository
 foreach ($repositories as $repository) {
 // Create a new GitPhp instance
 // Fetch the repository
 $git->fetch();
 // echo it out
 echo "Updated " . $repository->name . "\n";
 }
 }
}

Again I am just experimenting with it, so maybe it's wrong, I'm trying to figure it out for a larger project. Does anyone know what's going on?

You must be logged in to vote

Hi, this is correct error, there is no method CzProject\GitPhp\Git::fetch() - you must call this method on CzProject\GitPhp\GitRepository instance, for example:

$git = new Git;
// Collect Repositories
$repositories = repository::all();
// Fetch each repository
foreach ($repositories as $repository) {
 // Create a new GitPhp instance
 $repo = $git->open($pathToRepository);
 // Fetch the repository
 $repo->fetch();
 // echo it out
 echo "Updated " . $repository->name . "\n";
}

Replies: 1 comment 1 reply

Comment options

Hi, this is correct error, there is no method CzProject\GitPhp\Git::fetch() - you must call this method on CzProject\GitPhp\GitRepository instance, for example:

$git = new Git;
// Collect Repositories
$repositories = repository::all();
// Fetch each repository
foreach ($repositories as $repository) {
 // Create a new GitPhp instance
 $repo = $git->open($pathToRepository);
 // Fetch the repository
 $repo->fetch();
 // echo it out
 echo "Updated " . $repository->name . "\n";
}
You must be logged in to vote
1 reply
Comment options

Ahh okay thanks for your help, I get a little confused sometimes as I don't know which method the "use" statement should reference.

Answer selected by Lexian-droid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /