Search code examples
typescriptnodegit

How to get a status progress when cloning a repo via nodegit?


I use Clone.clone from nodegit and I am looking for a progress status callback. The function has a CheckoutOptions object, which I call like this:

var opts: CloneOptions = {};
opts.checkoutOpts = {
    progressCb: function() {
        console.log("Foo");
    },
}

But that seems to crash the BrowserWindow. Does anyone, by looking at the declaration of CheckoutOptions what I might do wrong?

Notice, CheckoutOptions is a member of CloneOptions


export class CheckoutOptions {
    version?: number;
    checkoutStrategy?: number;
    disableFilters?: number;
    dirMode?: number;
    fileMode?: number;
    fileOpenFlags?: number;
    notifyFlags?: number;
    notifyCb?: any;
    notifyPayload?: undefined;
    progressCb?: any;
    progressPayload?: undefined;
    paths?: Strarray | string | string[];
    baseline?: Tree;
    baselineIndex?: Index;
    targetDirectory?: string;
    ancestorLabel?: string;
    ourLabel?: string;
    theirLabel?: string;
    perfdataCb?: any;
    perfdataPayload?: undefined;
    [key: string]: any;
}

export class CloneOptions {
    version?: number;
    checkoutOpts?: CheckoutOptions;
    fetchOpts?: FetchOptions;
    bare?: number;
    local?: number;
    checkoutBranch?: string;
    repositoryCbPayload?: any;
    remoteCbPayload?: any;
}

Solution

  • Try initializing the checkout options using new CheckoutOptions() instead of using just an empty object {}.

    This version works:

    var opts = {};
    opts.checkoutOpts = new CheckoutOptions();
    opts.checkoutOpts.progressCb = function(){
        console.log("Foo");
    };
    

    and this version crashes:

    var opts = {};
    opts.checkoutOpts = {};
    opts.checkoutOpts.progressCb = function(){
        console.log("Foo");
    };