git::commit PHP Method

commit() static public method

static public commit ( $message, $author = null, $pathspec = null, $deferred = false )
    static function commit($message, $author = null, $pathspec = null, $deferred = false)
    {
        # clear status cache
        self::$status_cache = null;
        if ($deferred && gb::defer(array('gb', 'commit'), $message, $author, $pathspec, false)) {
            $pathspec = $pathspec ? r($pathspec) : '';
            gb::log('deferred commit -m %s --author %s %s', escapeshellarg($message), escapeshellarg($author), $pathspec);
            if (!$pathspec) {
                gb::log(LOG_WARNING, 'deferred commits without pathspec might cause unexpected changesets');
            }
            return true;
        }
        if ($pathspec) {
            $pathspec = ' ' . self::escargs($pathspec);
        } else {
            $pathspec = '';
        }
        $author = $author ? '--author=' . escapeshellarg($author) : '';
        git::exec('commit -m ' . escapeshellarg($message) . ' --quiet ' . $author . ' -- ' . $pathspec);
        @chmod(gb::$site_dir . '/.git/COMMIT_EDITMSG', 0664);
        return true;
    }

Usage Example

Example #1
0
        foreach ($state_fields as $k => $discard) {
            if ($k === 'body') {
                $modified_state[$k] = $post->rawBody();
            } else {
                $v = $post->{$k};
                if ($v instanceof GBDateTime) {
                    $v = strval($v);
                }
                $modified_state[$k] = $v;
            }
        }
    }
    # commit?
    if ($input['commit']) {
        git::add($post->name);
        git::commit(($created ? 'Created' : 'Updated') . ' post ' . r($post->title), gb::$authorized, $post->name);
    }
    # build response entity
    $rsp = array('name' => $post->name, 'version' => $post->id, 'exists' => $post->exists(), 'isTracked' => $post->isTracked(), 'isDirty' => $post->isDirty(), 'state' => $modified_state);
    # status
    $status = '200 OK';
    if ($created) {
        $status = '201 Created';
    }
    # send JSON response
    gb_admin::json_rsp($rsp, $status);
    gb::log('saved post %s', $post->name);
} catch (Exception $e) {
    gb::log('failed to save post: %s', GBException::format($e, true, false, null, 0));
    gb_admin::json_rsp($e->getMessage(), '400 Bad Request');
}
All Usage Examples Of git::commit