git | source tree | update git | Search

This code defines a function that compares two specific Git commits within a project, outputs the differences to a directory, and utilizes Gulp and Promises for task management.

Run example

npm run import -- "Display graphs of different commands and scenarios using dry-run"

Display graphs of different commands and scenarios using dry-run

var path = require('path');
var gulp = require('gulp');
var run = require('gulp-run');
var tap = require('gulp-tap');
var importer = require('../Core');
var gulpPromise = importer.import("gulp task to a Promise",
"{gulp}")

var PROFILE_PATH = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE || '';
var project = typeof project === 'undefined' ? path.join(PROFILE_PATH, 'Documents/portal') : project;

function getBranchBoundaries(p) {
    if(p) {
        project = p;
    }

    gulp.task('git watch', function () {
        return run('git diff -w a229417..498d5a5', {cwd: project})
            .pipe(tap(file => console.log(file)))
            .pipe(gulp.dest('output'))
    });

    return gulpPromise(['git watch'])
}
module.exports = getBranchBoundaries;

if(typeof $ !== 'undefined') {
    $.async();
    getBranchBoundaries(project)
        .then(r => $.sendResult(r))
        .catch(e => $.sendError(e))
}

What the code could have been:

const path = require('path');
const gulp = require('gulp');
const run = require('gulp-run');
const tap = require('gulp-tap');

const importer = require('../Core');
const gulpPromise = importer.import('gulp task to a Promise', {gulp});

const PROFILE_PATH = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE || '';
const DEFAULT_PROJECT_PATH = path.join(PROFILE_PATH, 'Documents/portal');
const PROJECT_PATH = process.env.PROJECT_PATH || DEFAULT_PROJECT_PATH;

gulp.task('git-watch', function () {
    return run(`git diff -w ${process.env.GIT_BRANCH_START_SHA}..${process.env.GIT_BRANCH_END_SHA}`, {cwd: PROJECT_PATH})
       .pipe(tap(file => console.log(file)))
       .pipe(gulp.dest('output'));
});

module.exports = function getBranchBoundaries(p = PROJECT_PATH) {
    // Get project path from environment variable if provided, otherwise use default value
    if (p) {
        PROJECT_PATH = p;
    }

    // Return a promise that resolves when the 'git-watch' task is completed
    return gulpPromise(['git-watch']);
};

if (typeof $!== 'undefined') {
    $.async();
    getBranchBoundaries().then(r => $.sendResult(r)).catch(e => $.sendError(e));
}

This code defines a function getBranchBoundaries that executes a Git command to compare two specific commits within a project and outputs the differences to a "output" directory.

Here's a breakdown:

  1. Imports:

  2. Configuration:

  3. getBranchBoundaries Function:

  4. Execution:

In essence, this code provides a way to compare two Git commits within a project and visualize the differences using Gulp and a custom Promise-based task execution mechanism.