<commit_before>import { Ref } from "./ref";
import { createLog, GitLog } from "./gitLog";
import { GerritSettings, IGerritSettings } from "../common/settings";
import { Logger, LoggerSingleton } from "../view/logger";
import * as utils from "../common/utils";
import * as common from "../common/common";
import { Gerrit, IGerrit } from "./gerrit";
import * as exec from "../common/exec";

interface IGit {
    stage(path: string): Promise<string>;
    reset(path: string, hard?: boolean): Promise<string>;
    clean(path: string): Promise<string>;
    commit(msg: string, amend: boolean): Promise<string>;
    checkoutBranch(branch: string): Promise<string>;
    checkoutRef(ref: Ref): Promise<string>;
    cherrypickRef(ref: Ref): Promise<string>;
    fetchRef<T>(ref: Ref, resolver: (url: string) => Promise<string>): Promise<string>;
    fetch(url: string, options?: string[], origin?: string): Promise<string>;
    checkout(HEAD: string): Promise<string>;
    cherrypick(HEAD: string): Promise<string>;
    cherrypickContinue(): Promise<string>;
    push(target: string[], origin?: string): Promise<string>;
    rebase(branch: string): Promise<string>;
    rebaseContinue(): Promise<string>;
    getGitLog(index: number): Promise<GitLog>;
    git(gitCommand: string, options?: string[], args?: string[], stdin?: string): Promise<string>;
}

class GitClass implements IGit {
    private settings: IGerritSettings;
    private logger: LoggerSingleton;
    private cherrypickActive: boolean;
    private rebaseActive: boolean;
    private gerrit: IGerrit;

    constructor() {
        this.gerrit = Gerrit;
        this.settings = GerritSettings;
        this.logger = Logger.logger;
        this.cherrypickActive = false;
        this.rebaseActive = false;
    }

    public stage(path: string): Promise<string> {
        let args = [
            path
        ];
        return this.git("add", [], args);
    }

    public reset(path: string, hard?: boolean): Promise<string> {
        hard = utils.setDefault(hard, false);
        let args: string[] = [
            path
        ];
        let options: string[] = [];
        if (hard) {
            options.push("--hard");
        }
        return this.git("reset", options, args);
    }

    public clean(path: string): Promise<string> {
        return this.checkout(path);
    }

    public commit(msg: string, amend: boolean): Promise<string> {
        return new Promise((resolve, reject) => {
            let options: string[] = [];
            if (amend) {
                options.push("--amend", "--no-edit");
            } else {
                if (msg === null || msg.length === 0) {
                    let reason: common.RejectReason = {
                        showInformation: true,
                        message: "Requires a message to commit with",
                        type: common.RejectType.DEFAULT
                    };
                    reject(reason);
                }
                options.push("--file", "-");
            }
            this.git("commit", options, [], (!amend) ? msg : null).then(value => {
                resolve(value);
            }, reason => {
                reject(reason);
            });
        });
    }

    public checkoutBranch(branch: string): Promise<string> {
        return this.fetch("", ["-fv"]).then(fetchValue => {
            return this.checkout(`origin/${branch}`).then(checkoutValue => {
                this.gerrit.setBranch(branch);
                return checkoutValue;
            });
        });
    }

    public checkoutRef(ref: Ref): Promise<string> {
        return this.fetchRef(ref, this.checkout);
    }

    public cherrypickRef(ref: Ref): Promise<string> {
        return this.fetchRef(ref, this.cherrypick);
    }

    public fetchRef<T>(ref: Ref, resolver: (url: string) => Promise<string>): Promise<string> {
        return new Promise((resolve, reject) => {
            this.gerrit.isDirty().then(dirty => {
                if (dirty) {
                    let reason: common.RejectReason = {
                        showInformation: true,
                        message: "Dirty Head",
                        type: common.RejectType.DEFAULT
                    };
                    reject(reason);
                    return;
                }

                this.gerrit.setCurrentRef(ref);

                this.fetch(ref.getUrl()).then(value => {
                    resolver.apply(this, ["FETCH_HEAD"]).then(value => {
                        resolve(value);
                    }, reason => {
                        reject(reason);
                        return;
                    });
                }, reason => {
                    reject(reason);
                    return;
                });
            }, reason => {
                reject(reason);
                return;
            });
        });
    }

    public fetch(url: string, options?: string[], origin?: string): Promise<string> {
        url = utils.setDefault(url, "");
        options = utils.setDefault(options, []);
        origin = utils.setDefault(origin, "origin");
        let args: string[] = [
            origin
        ];
        if (url.length > 0) {
            args.push(url);
        }
        return this.git("fetch", options, args);
    }

    public checkout(HEAD: string): Promise<string> {
        let options = [
            HEAD
        ];
        return this.git("checkout", options);
    }

    public cherrypick(HEAD: string): Promise<string> {<commit_msg>Remove gerrit methods from git<commit_after>import { Ref } from "./ref";
import { createLog, GitLog } from "./gitLog";
import { GerritSettings, IGerritSettings } from "../common/settings";
import { Logger, LoggerSingleton } from "../view/logger";
import * as utils from "../common/utils";
import * as common from "../common/common";
import { Gerrit, IGerrit } from "./gerrit";
import * as exec from "../common/exec";

interface IGit {
    stage(path: string): Promise<string>;
    reset(path: string, hard?: boolean): Promise<string>;
    clean(path: string): Promise<string>;
    commit(msg: string, amend: boolean): Promise<string>;
    fetch(url: string, options?: string[], origin?: string): Promise<string>;
    checkout(HEAD: string): Promise<string>;
    cherrypick(HEAD: string): Promise<string>;
    cherrypickContinue(): Promise<string>;
    push(target: string[], origin?: string): Promise<string>;
    rebase(branch: string): Promise<string>;
    rebaseContinue(): Promise<string>;
    getGitLog(index: number): Promise<GitLog>;
    git(gitCommand: string, options?: string[], args?: string[], stdin?: string): Promise<string>;
}

class GitClass implements IGit {
    private settings: IGerritSettings;
    private logger: LoggerSingleton;
    private cherrypickActive: boolean;
    private rebaseActive: boolean;
    private gerrit: IGerrit;

    constructor() {
        this.gerrit = Gerrit;
        this.settings = GerritSettings;
        this.logger = Logger.logger;
        this.cherrypickActive = false;
        this.rebaseActive = false;
    }

    public stage(path: string): Promise<string> {
        let args = [
            path
        ];
        return this.git("add", [], args);
    }

    public reset(path: string, hard?: boolean): Promise<string> {
        hard = utils.setDefault(hard, false);
        let args: string[] = [
            path
        ];
        let options: string[] = [];
        if (hard) {
            options.push("--hard");
        }
        return this.git("reset", options, args);
    }

    public clean(path: string): Promise<string> {
        return this.checkout(path);
    }

    public commit(msg: string, amend: boolean): Promise<string> {
        return new Promise((resolve, reject) => {
            let options: string[] = [];
            if (amend) {
                options.push("--amend", "--no-edit");
            } else {
                if (msg === null || msg.length === 0) {
                    let reason: common.RejectReason = {
                        showInformation: true,
                        message: "Requires a message to commit with",
                        type: common.RejectType.DEFAULT
                    };
                    reject(reason);
                }
                options.push("--file", "-");
            }
            this.git("commit", options, [], (!amend) ? msg : null).then(value => {
                resolve(value);
            }, reason => {
                reject(reason);
            });
        });
    }

    public fetch(url: string, options?: string[], origin?: string): Promise<string> {
        url = utils.setDefault(url, "");
        options = utils.setDefault(options, []);
        origin = utils.setDefault(origin, "origin");
        let args: string[] = [
            origin
        ];
        if (url.length > 0) {
            args.push(url);
        }
        return this.git("fetch", options, args);
    }

    public checkout(HEAD: string): Promise<string> {
        let options = [
            HEAD
        ];
        return this.git("checkout", options);
    }

    public cherrypick(HEAD: string): Promise<string> {
{'fraction_non_alphanumeric': 0.14095570586951778, 'fraction_numerical': 0.0004363953742090334, 'mean_word_length': 1.9390830394357166, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7415746', 'n_tokens_mistral': 2516, 'n_tokens_neox': 2411, 'n_words': 589}