Best JavaScript code snippet using best
Git.js
Source:Git.js
1/*2 This file acts as an entry point to GitCli.js and other possible3 implementations of Git communication besides Cli. Application4 should not access GitCli directly.5*/6define(function (require, exports) {7 // Local modules8 var Preferences = require("src/Preferences"),9 Promise = require("bluebird"),10 GitCli = require("src/git/GitCli"),11 Utils = require("src/Utils");12 // Implementation13 function pushToNewUpstream(remoteName, remoteBranch) {14 return GitCli.push(remoteName, remoteBranch, ["--set-upstream"]);15 }16 function getRemoteUrl(remote) {17 return GitCli.getConfig("remote." + remote + ".url");18 }19 function setRemoteUrl(remote, url) {20 return GitCli.setConfig("remote." + remote + ".url", url);21 }22 function sortBranches(branches) {23 return branches.sort(function (a, b) {24 var ar = a.remote || "",25 br = b.remote || "";26 // origin remote first27 if (br && ar === "origin" && br !== "origin") {28 return -1;29 } else if (ar && ar !== "origin" && br === "origin") {30 return 1;31 }32 // sort by remotes33 if (ar < br) {34 return -1;35 } else if (ar > br) {36 return 1;37 }38 // sort by sortPrefix (# character)39 if (a.sortPrefix < b.sortPrefix) {40 return -1;41 } else if (a.sortPrefix > b.sortPrefix) {42 return 1;43 }44 // master branch first45 if (a.sortName === "master" && b.sortName !== "master") {46 return -1;47 } else if (a.sortName !== "master" && b.sortName === "master") {48 return 1;49 }50 // sort by sortName (lowercased branch name)51 return a.sortName < b.sortName ? -1 : a.sortName > b.sortName ? 1 : 0;52 });53 }54 function getBranches() {55 return GitCli.getBranches().then(function (branches) {56 return sortBranches(branches);57 });58 }59 function getAllBranches() {60 return GitCli.getAllBranches().then(function (branches) {61 return sortBranches(branches);62 });63 }64 function getHistory(branch, skip) {65 return GitCli.getHistory(branch, skip);66 }67 function getFileHistory(file, branch, skip) {68 return GitCli.getHistory(branch, skip, file);69 }70 function resetIndex() {71 return GitCli.reset();72 }73 function discardAllChanges() {74 return GitCli.reset("--hard").then(function () {75 return GitCli.clean();76 });77 }78 function getMergeInfo() {79 var baseCheck = ["MERGE_MODE", "rebase-apply"],80 mergeCheck = ["MERGE_HEAD", "MERGE_MSG"],81 rebaseCheck = ["rebase-apply/next", "rebase-apply/last", "rebase-apply/head-name"],82 gitFolder = Preferences.get("currentGitRoot") + ".git/";83 return Promise.all(baseCheck.map(function (fileName) {84 return Utils.loadPathContent(gitFolder + fileName);85 })).spread(function (mergeMode, rebaseMode) {86 var obj = {87 mergeMode: mergeMode !== null,88 rebaseMode: rebaseMode !== null89 };90 if (obj.mergeMode) {91 return Promise.all(mergeCheck.map(function (fileName) {92 return Utils.loadPathContent(gitFolder + fileName);93 })).spread(function (head, msg) {94 if (head) {95 obj.mergeHead = head.trim();96 }97 var msgSplit = msg ? msg.trim().split(/conflicts:/i) : [];98 if (msgSplit[0]) {99 obj.mergeMessage = msgSplit[0].trim();100 }101 if (msgSplit[1]) {102 obj.mergeConflicts = msgSplit[1].trim().split("\n").map(function (line) { return line.trim(); });103 }104 return obj;105 });106 }107 if (obj.rebaseMode) {108 return Promise.all(rebaseCheck.map(function (fileName) {109 return Utils.loadPathContent(gitFolder + fileName);110 })).spread(function (next, last, head) {111 if (next) { obj.rebaseNext = next.trim(); }112 if (last) { obj.rebaseLast = last.trim(); }113 if (head) { obj.rebaseHead = head.trim().substring("refs/heads/".length); }114 return obj;115 });116 }117 return obj;118 });119 }120 function discardFileChanges(file) {121 return GitCli.unstage(file).then(function () {122 return GitCli.checkout(file);123 });124 }125 function pushForced(remote, branch) {126 return GitCli.push(remote, branch, ["--force"]);127 }128 function deleteRemoteBranch(remote, branch) {129 return GitCli.push(remote, branch, ["--delete"]);130 }131 function undoLastLocalCommit() {132 return GitCli.reset("--soft", "HEAD~1");133 }134 // Public API135 exports.pushToNewUpstream = pushToNewUpstream;136 exports.getBranches = getBranches;137 exports.getAllBranches = getAllBranches;138 exports.getHistory = getHistory;139 exports.getFileHistory = getFileHistory;140 exports.resetIndex = resetIndex;141 exports.discardAllChanges = discardAllChanges;142 exports.getMergeInfo = getMergeInfo;143 exports.discardFileChanges = discardFileChanges;144 exports.getRemoteUrl = getRemoteUrl;145 exports.setRemoteUrl = setRemoteUrl;146 exports.pushForced = pushForced;147 exports.deleteRemoteBranch = deleteRemoteBranch;148 exports.undoLastLocalCommit = undoLastLocalCommit;149 Object.keys(GitCli).forEach(function (method) {150 if (!exports[method]) {151 exports[method] = GitCli[method];152 }153 });...
run_compare.ts
Source:run_compare.ts
1/*2 * Copyright (c) 2019, salesforce.com, inc.3 * All rights reserved.4 * SPDX-License-Identifier: MIT5 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT6*/7import { compareBenchmarkStats } from '@best/compare';8import { beginBenchmarkComparisonCheck, completeBenchmarkComparisonCheck, failedBenchmarkComparisonCheck, updateLatestRelease } from '@best/github-integration';9import { runBest } from './run_best';10import git from 'simple-git/promise';11import { FrozenProjectConfig, FrozenGlobalConfig, BenchmarkComparison } from '@best/types';12const STORAGE_FS = '@best/store-fs';13const isHex = (x:string) => /^[0-9a-fA-F]+$/.test(x);14const normalizeCommit = async (commit: string, gitCLI: any) => {15 if (commit === 'current') {16 const result = await gitCLI.log();17 commit = result.latest.hash;18 }19 if (!isHex(commit)) {20 // If is not hexadecimal we try to look for a local branch21 commit = await gitCLI.revparse([commit]);22 }23 return commit.slice(0, 7);24};25export async function runCompare(globalConfig: FrozenGlobalConfig, configs: FrozenProjectConfig[], outputStream: NodeJS.WriteStream): Promise<BenchmarkComparison | undefined> {26 const { gitInfo: { localChanges }, rootDir, gitIntegration, externalStorage, compareStats = [] } = globalConfig;27 const gitCLI = git(rootDir);28 const status = await gitCLI.status();29 const initialBranch = status.current;30 let baseCommit = compareStats[0] || 'master';31 let compareCommit = compareStats[1] || (localChanges ? 'local' : 'current');32 let stashedLocalChanges = false;33 if (compareStats.length > 2) {34 throw new Error('Cannot compare more than 2 commits.');35 }36 // Get commit hash substrings.37 baseCommit = await normalizeCommit(baseCommit, gitCLI);38 if (compareCommit !== 'local') {39 compareCommit = await normalizeCommit(compareCommit, gitCLI);40 }41 if (baseCommit === compareCommit) {42 console.log(`Hash of commits are identical (${baseCommit}). Skipping comparison`);43 return;44 }45 let check, gitHubInstallation;46 if (gitIntegration) {47 const github = await beginBenchmarkComparisonCheck(compareCommit, globalConfig);48 check = github.check;49 gitHubInstallation = github.gitHubInstallation;50 }51 try {52 const projectNames = configs.map((cfg: any) => cfg.projectName);53 const runConfig = { ...globalConfig, gitLocalChanges: false };54 let storageProvider;55 // If not external storage we will run the benchmarks and compare using fs56 if (!externalStorage) {57 storageProvider = require(STORAGE_FS);58 storageProvider.initialize({ rootDir });59 if (localChanges) {60 await gitCLI.stash({ '--include-untracked': true });61 stashedLocalChanges = true;62 }63 // Run base commit.64 await gitCLI.checkout(baseCommit);65 await runBest({ ...runConfig, gitInfo: { ...runConfig.gitInfo, lastCommit: { ...runConfig.gitInfo.lastCommit, hash: baseCommit }} }, configs, outputStream);66 // Run local changes or compare commit.67 if (compareCommit === 'local') {68 await gitCLI.checkout(initialBranch);69 if (stashedLocalChanges) {70 await gitCLI.stash(['pop']);71 }72 } else {73 await gitCLI.checkout(compareCommit);74 }75 await runBest({ ...runConfig, gitInfo: { ...runConfig.gitInfo, lastCommit: { ...runConfig.gitInfo.lastCommit, hash: compareCommit }} }, configs, outputStream);76 // Return local files to their initial state no matter what happens.77 await gitCLI.checkout(initialBranch);78 if (stashedLocalChanges) {79 await gitCLI.stash(['pop']);80 }81 } else {82 try {83 storageProvider = require(externalStorage);84 storageProvider.initialize({});85 } catch (err) {86 throw new Error(`Can't resolve the externalStorage ${externalStorage}`);87 }88 }89 const compareResults = await compareBenchmarkStats(baseCommit, compareCommit, projectNames, storageProvider);90 if (gitIntegration && gitHubInstallation && check) {91 await completeBenchmarkComparisonCheck(gitHubInstallation, check, compareResults, globalConfig);92 }93 if (gitIntegration) {94 updateLatestRelease(projectNames, globalConfig);95 }96 return compareResults;97 } catch (err) {98 if (gitIntegration && gitHubInstallation && check) {99 await failedBenchmarkComparisonCheck(gitHubInstallation, check, err.toString(), globalConfig);100 }101 throw err;102 }...
index.ts
Source:index.ts
1import { ContainerPublisher } from 'ern-container-publisher'2import { createTmpDir, gitCli, shell, log, NativePlatform } from 'ern-core'3import fs from 'fs'4import path from 'path'5export default class GitPublisher implements ContainerPublisher {6 get name(): string {7 return 'git'8 }9 get platforms(): NativePlatform[] {10 return ['android', 'ios']11 }12 public async publish({13 containerPath,14 containerVersion,15 url,16 platform,17 extra,18 }: {19 containerPath: string20 containerVersion: string21 url?: string,22 platform: string,23 extra?: {24 branch?: string,25 subdir?: string,26 allowVersionOverwrite?: boolean27 }28 }) {29 const workingGitDir = createTmpDir()30 const branch = (extra && extra.branch) || 'master'31 const subdir = (extra && extra.subdir) || ''32 const allowVersionOverwrite = (extra && extra.allowVersionOverwrite) || false33 if (!url) {34 throw new Error('url is required')35 }36 try {37 shell.pushd(workingGitDir)38 const git = gitCli()39 const re = new RegExp(`refs/heads/${branch}`)40 const remoteHeads = await gitCli().raw(['ls-remote', '--heads', url])41 log.debug(`workingGitDir: ${workingGitDir}`)42 if (re.test(remoteHeads)) {43 log.debug(`${branch} branch exists in remote. Reusing it.`)44 log.debug(`Running 'git clone ${url} . --single-branch --branch ${branch} --depth 1`)45 await gitCli().clone(url, '.', ['--single-branch', '--branch', branch, '--depth', '1'])46 } else {47 log.debug(`${branch} branch does not exists in remote. Creating it.`)48 log.debug(`Running 'git clone ${url} . --depth 1`)49 await gitCli().clone(url, '.', ['--depth', '1'])50 await git.checkoutLocalBranch(branch)51 }52 const projectDir = path.join(workingGitDir, subdir);53 shell.rm('-rf', path.join(projectDir, '*'))54 if (subdir) {55 // Normally that wouldn't be needed as the -f in cp should create the folder if it does not exist56 // but that is not working somehow in shelljs57 shell.mkdir(projectDir)58 }59 shell.cp('-Rf', path.join(containerPath, '{.*,*}'), projectDir)60 if (platform === 'ios') {61 this.patchContainerInfoPlistWithVersion({containerPath: projectDir, containerVersion})62 }63 await git.add(subdir ? subdir : './*')64 await git.commit(`Container v${containerVersion}`)65 const tagsOptions = allowVersionOverwrite ? ['-f'] : []66 await git.tag([`v${containerVersion}`, ...tagsOptions])67 await git.push('origin', branch)68 await git.raw(['push', 'origin', '--tags', ...tagsOptions])69 log.info('[=== Completed publication of the Container ===]')70 log.info(`[Publication url : ${url}]`)71 log.info(`[Git Branch: ${branch}]`)72 if (subdir) {73 log.info(`[Subdirectory : ${subdir}]`)74 }75 log.info(`[Git Tag: v${containerVersion}]`)76 } finally {77 shell.popd()78 }79 }80 /**81 * [iOS Specific]82 * Patch ElectrodeContainer Info.plist to update CFBundleShortVersionString83 * with the Container version being published84 */85 public patchContainerInfoPlistWithVersion({86 containerPath,87 containerVersion88 } : {89 containerPath: string,90 containerVersion: string91 }) {92 const infoPlistPath = path.join(containerPath, 'ElectrodeContainer', 'Info.plist')93 if (fs.existsSync(infoPlistPath)) {94 const infoPlist = fs.readFileSync(infoPlistPath).toString()95 const patchedInfoPlist = infoPlist.replace(96 new RegExp('<key>CFBundleShortVersionString<\/key>\\n\\t<string>.+<\/string>'),97 `<key>CFBundleShortVersionString</key>\n\t<string>${containerVersion.replace('-raw', '')}</string>`)98 fs.writeFileSync(infoPlistPath, patchedInfoPlist)99 }100 }...
Using AI Code Generation
1var bestGit = require('best-git');2bestGit.gitCLI('status', function(err, data) {3 if(err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var bestGit = require('best-git');10bestGit.gitCLI('status', function(err, data) {11 if(err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var bestGit = require('best-git');18bestGit.gitCLI('status', function(err, data) {19 if(err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var bestGit = require('best-git');26bestGit.gitCLI('status', function(err, data) {27 if(err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var bestGit = require('best-git');34bestGit.gitCLI('status', function(err, data) {35 if(err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var bestGit = require('best-git');42bestGit.gitCLI('status', function(err, data) {43 if(err) {44 console.log(err);45 } else {46 console.log(data);47 }48});49var bestGit = require('best-git');50bestGit.gitCLI('status', function(err, data) {51 if(err) {52 console.log(err);53 } else {54 console.log(data);55 }56});57var bestGit = require('best-git');58bestGit.gitCLI('status', function(err, data) {59 if(err) {60 console.log(err);61 } else {62 console.log(data);63 }64});
Using AI Code Generation
1var gitCLI = require('bestlib').gitCLI;2gitCLI.init();3gitCLI.status();4gitCLI.add();5gitCLI.commit();6gitCLI.push();7gitCLI.pull();8var gitAPI = require('bestlib').gitAPI;9gitAPI.init();10gitAPI.status();11gitAPI.add();12gitAPI.commit();13gitAPI.push();14gitAPI.pull();15var gitAPI = require('bestlib').gitAPI;16gitAPI.init();17gitAPI.status();18gitAPI.add();19gitAPI.commit();20gitAPI.push();21gitAPI.pull();22var gitAPI = require('bestlib').gitAPI;23gitAPI.init();24gitAPI.status();25gitAPI.add();26gitAPI.commit();27gitAPI.push();28gitAPI.pull();29var gitAPI = require('bestlib').gitAPI;30gitAPI.init();31gitAPI.status();32gitAPI.add();33gitAPI.commit();34gitAPI.push();35gitAPI.pull();36var gitAPI = require('bestlib').gitAPI;37gitAPI.init();38gitAPI.status();39gitAPI.add();40gitAPI.commit();41gitAPI.push();42gitAPI.pull();43var gitAPI = require('bestlib').gitAPI;44gitAPI.init();45gitAPI.status();46gitAPI.add();47gitAPI.commit();48gitAPI.push();49gitAPI.pull();50var gitAPI = require('bestlib').gitAPI;51gitAPI.init();52gitAPI.status();53gitAPI.add();54gitAPI.commit();55gitAPI.push();56gitAPI.pull();57var gitAPI = require('bestlib').gitAPI;58gitAPI.init();59gitAPI.status();60gitAPI.add();61gitAPI.commit();62gitAPI.push();63gitAPI.pull();64var gitAPI = require('bestlib').gitAPI
Using AI Code Generation
1var BestGit = require('./bestgit');2var bestgit = new BestGit();3bestgit.gitCLI('git status');4var BestGit = require('./bestgit');5var bestgit = new BestGit();6bestgit.gitCLI('git status', function (err, data) {7 if (err) {8 console.log(err);9 } else {10 console.log(data);11 }12});13var BestGit = require('./bestgit');14var bestgit = new BestGit();15bestgit.gitCLI('git status', function (err, data) {16 if (err) {17 console.log(err);18 } else {19 console.log(data);20 }21}, {cwd: '/path/to/your/repo'});22var BestGit = require('./bestgit');23var bestgit = new BestGit();24bestgit.gitCLI('git status', function (err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30}, {cwd: '/path/to/your/repo', encoding: 'binary'});31var BestGit = require('./bestgit');32var bestgit = new BestGit();33bestgit.gitCLI('git status', function (err, data) {34 if (err) {35 console.log(err);36 } else {37 console.log(data);38 }39}, {cwd: '/path/to/your/repo', encoding: 'binary'}, function (err, data) {40 if (err) {41 console.log(err);
Using AI Code Generation
1var BestGit = require('bestgit');2var gitCLI = new BestGit.gitCLI();3gitCLI.status(function(err, data) {4 console.log(data);5});6gitCLI.add('.', function(err, data) {7 console.log(data);8});9gitCLI.commit('test commit', function(err, data) {10 console.log(data);11});12gitCLI.push('origin', 'master', function(err, data) {13 console.log(data);14});15gitCLI.pull('origin', 'master', function(err, data) {16 console.log(data);17});18var BestGit = require('bestgit');19var gitCLI = new BestGit.gitCLI();20gitCLI.status(function(err, data) {21 console.log(data);22});23gitCLI.add('.', function(err, data) {24 console.log(data);25});26gitCLI.commit('test commit', function(err, data) {27 console.log(data);28});29gitCLI.push('origin', 'master', function(err, data) {30 console.log(data);31});32gitCLI.pull('origin', 'master', function(err, data) {33 console.log(data);34});35var BestGit = require('bestgit');36var gitCLI = new BestGit.gitCLI();37gitCLI.status(function(err, data) {38 console.log(data);39});40gitCLI.add('.', function(err, data) {41 console.log(data);42});43gitCLI.commit('test commit', function(err, data) {44 console.log(data);45});46gitCLI.push('origin', 'master', function(err, data) {47 console.log(data);48});49gitCLI.pull('origin', 'master', function(err, data) {50 console.log(data);51});52var BestGit = require('bestgit');53var gitCLI = new BestGit.gitCLI();54gitCLI.status(function(err, data) {55 console.log(data);56});57gitCLI.add('.', function(err, data) {58 console.log(data);59});60gitCLI.commit('test commit', function(err, data) {61 console.log(data);62});63gitCLI.push('origin', 'master', function(err, data) {64 console.log(data);65});66gitCLI.pull('origin', 'master', function(err, data) {67 console.log(data);
Using AI Code Generation
1var bestGlobals = require('best-globals');2var gitCLI = new bestGlobals.gitCLI();3gitCLI.init();4gitCLI.add('test4.js');5gitCLI.commit('test4.js');6gitCLI.push('origin', 'master');
Using AI Code Generation
1var git = new BestGit();2git.gitCLI("add .", function(err, data){3 if(err) console.log(err);4 if(data) console.log(data);5});6git.gitCLI("commit -m 'test4'", function(err, data){7 if(err) console.log(err);8 if(data) console.log(data);9});10git.gitCLI("push", function(err, data){11 if(err) console.log(err);12 if(data) console.log(data);13});14var git = new BestGit();15git.gitCLI("add .", function(err, data){16 if(err) console.log(err);17 if(data) console.log(data);18});19git.gitCLI("commit -m 'test5'", function(err, data){20 if(err) console.log(err);21 if(data) console.log(data);22});23git.gitCLI("push", function(err, data){24 if(err) console.log(err);25 if(data) console.log(data);26});27var git = new BestGit();28git.gitCLI("add .", function(err, data){29 if(err) console.log(err);30 if(data) console.log(data);31});32git.gitCLI("commit -m 'test6'", function(err, data){33 if(err) console.log(err);34 if(data) console.log(data);35});36git.gitCLI("push", function(err, data){37 if(err) console.log(err);38 if(data) console.log(data);39});40var git = new BestGit();41git.gitCLI("add .", function(err, data){42 if(err) console.log(err);43 if(data) console.log(data);44});45git.gitCLI("commit -m 'test7'", function(err, data){46 if(err) console.log(err);47 if(data) console.log(data);48});49git.gitCLI("push", function(err, data){50 if(err) console.log(err);51 if(data) console.log(data);52});53var git = new BestGit();54git.gitCLI("add .", function(err, data){55 if(err) console.log(err);56 if(data) console.log(data);57});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!