Skip to content

Repositories created by Pitmaster::init() never write reflogs #8

Closed

Description

@dnnsjsk

Repositories created with Pitmaster::init() (and clone(), which calls it) never get reflogs. pitmaster reflog prints nothing after commits, checkouts and resets, and HEAD@{n}-style recovery has no data.

git writes reflogs by default in repositories with a working tree when core.logAllRefUpdates is unset, and git init also writes logallrefupdates = true explicitly. Pitmaster only writes a reflog entry when core.logallrefupdates is true or the log file already exists (

pitmaster/src/Repository.php

Lines 5091 to 5100 in 5beb97d

private function shouldWriteReflog(string $refName): bool
{
if ($this->config->getBool('core.logallrefupdates')) {
return true;
}
$path = ($refName === 'HEAD' ? $this->gitDir : $this->commonDir) . '/logs/' . $refName;
return is_file($path);
}
), and Pitmaster::init() does not set the key (

pitmaster/src/Pitmaster.php

Lines 232 to 262 in 5beb97d

private static function initialConfig(string $path, string $objectFormat = 'sha1'): string
{
if (!in_array($objectFormat, ['sha1', 'sha256'], true)) {
throw new \InvalidArgumentException("Unsupported object format: {$objectFormat}");
}
$lines = [
'[core]',
"\trepositoryformatversion = " . ($objectFormat === 'sha256' ? '1' : '0'),
"\tfilemode = true",
"\tbare = false",
];
if (self::isCaseInsensitiveFilesystem($path)) {
$lines[] = "\tignorecase = true";
}
if (PHP_OS_FAMILY === 'Darwin') {
$lines[] = "\tprecomposeunicode = true";
}
$lines[] = '';
if ($objectFormat === 'sha256') {
$lines[] = '[extensions]';
$lines[] = "\tobjectformat = sha256";
$lines[] = '';
}
return implode("\n", $lines);
}
).

Repro

pitmaster init && git config user.name T && git config user.email t@x
echo a > a.txt && pitmaster add a.txt && pitmaster commit -m first
pitmaster reflog        # prints nothing
ls .git/logs            # no HEAD, no refs/heads/main

Repositories created by git init are not affected because their config sets the key.

Expected

Either write logallrefupdates = true in the initial config of non-bare repositories, or treat an unset key as true for non-bare repositories, as git does.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions