Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Change GitChanges so it compares against the remote #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ module.exports = function (grunt) {
if (options.changes) {
args.push('--changes');
}
if (options.gitRemote) {
args.push('--git-remote', options.gitRemote);
}
if (options.debug) {
args.push('--debug');
}
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ optimist.boolean('single-thread');
optimist.boolean('changes');
optimist.default('changes', false);

optimist.string('git-remote');
optimist.default('git-remote', 'origin');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please replace origin to master...HEAD

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason I didn't opt for that approach was that it always compares against master. What I was going for with the origin approach was to compare against the current branch's tracked remote branch. The issue you might be seeing is that the branch you are working off of doesn't exist in the remote repo. I am not sure I tested that case, but I will do so shortly to confirm.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm I just ran git diff --name-only origin on a brach that isn't in the remote repo and it worked correctly for me (showing in the diagram above both the committed and unstaged changes that were not yet pushed to origin, essentially everything I have done locally since the last pull/rebase).

What were you seeing for results?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is your remote named origin? I am assuming yes because that is the default behavior, but just double checking.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for late reply.
I tried git diff --name-only origin. but it failed.

$  git branch
* jdonaghue-master
  master
  refactor-code-format
  use-es6-default
$ git diff --name-only origin
fatal: ambiguous argument 'origin': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

is that command works fine in all situations?

$ git remote -v                                                                                                                 128 ↵
base    [email protected]:DefinitelyTyped/definition-tester.git (fetch)
base    [email protected]:DefinitelyTyped/definition-tester.git (push)
origin  [email protected]:vvakame/definition-tester.git (fetch)
origin  [email protected]:vvakame/definition-tester.git (push)
$ git diff --name-only base
fatal: ambiguous argument 'base': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'


optimist.boolean('dry');
optimist.default('dry', false);

Expand Down Expand Up @@ -91,6 +94,7 @@ new TestRunner({
tslintConfig: path.join(path.dirname(testerPkgPath), 'conf', 'tslint.json'),

changes: (testFull ? false : argv['changes']),
gitRemote: argv['git-remote'],
tests: argv['dry'] ? false : argv['tests'],
lint: argv['dry'] ? false : argv['lint'],
headers: argv['dry'] ? false : argv['headers'],
Expand Down
1 change: 1 addition & 0 deletions src/test/ITestOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface ITestOptions {
tslintConfig: string;

changes: boolean;
gitRemote: string;
tests: boolean;
lint: boolean;
headers: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/test/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class TestRunner {
this.options = options;

this.index = new FileIndex(this.options);
this.changes = new GitChanges(this.options.dtPath);
this.changes = new GitChanges(this.options.dtPath, this.options.gitRemote);

let tscVersion = 'unknown';
try {
Expand Down
7 changes: 5 additions & 2 deletions src/util/GitChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ import * as util from './util';
export default class GitChanges {

private dtPath: string;
private remote: string;

constructor(dtPath: string) {
constructor(dtPath: string, remote: string) {
this.dtPath = dtPath;
this.remote = remote;
}

public readChanges(): Promise<string[]> {
let dir = path.join(this.dtPath, '.git');
const remote = this.remote;

return util.fileExists(dir).then((exists) => {
if (!exists) {
throw new Error('cannot locate git-dir: ' + dir);
}
return new Promise<string[]>((resolve: (result: string[]) => void, reject: (error: any) => void) => {
let args = ['--name-only HEAD~1'];
let args = ['--name-only ' + remote];
let opts = {};
let git = new Git({
'git-dir': dir
Expand Down