Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
wmertens committed Feb 2, 2021
1 parent 65b6720 commit e9b9fd1
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 89 deletions.
18 changes: 11 additions & 7 deletions components/graph/git-graph-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Move extends ActionBase {

class Reset extends ActionBase {
constructor(graph, node) {
super(graph, 'Reset', 'reset', octicons.trashcan.toSVG({ 'height': 18 }));
super(graph, 'Reset', 'reset', octicons.trashcan.toSVG({ height: 18 }));
this.node = node;
this.visible = ko.computed(() => {
if (this.isRunning()) return true;
Expand All @@ -95,7 +95,8 @@ class Reset extends ActionBase {
context &&
context.node() &&
remoteRef.node() != context.node() &&
remoteRef.node().timestamp < context.node().timestamp;
remoteRef.node().timestamp < context.node().timestamp
);
});
}

Expand Down Expand Up @@ -222,11 +223,14 @@ class Push extends ActionBase {
if (remoteRef) {
return remoteRef.moveTo(ref.node().sha1);
} else {
return ref.createRemoteRef().then(() => {
if (this.graph.HEAD().name == ref.name) {
this.grah.HEADref().node(ref.node());
}
}).finally(() => programEvents.dispatch({ event: 'request-fetch-tags' }));
return ref
.createRemoteRef()
.then(() => {
if (this.graph.HEAD().name == ref.name) {
this.grah.HEADref().node(ref.node());
}
})
.finally(() => programEvents.dispatch({ event: 'request-fetch-tags' }));
}
}
}
Expand Down
72 changes: 35 additions & 37 deletions components/graph/git-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,43 +116,7 @@ class GitNodeViewModel extends Animateable {
new GraphActions.Squash(this.graph, this),
];

this.render = _.debounce(
() => {
this.refSearchFormVisible(false);
if (!this.isInited) return;
if (this.ancestorOfHEAD()) {
this.r(30);
this.cx(610);

if (!this.aboveNode) {
this.cy(120);
} else if (this.aboveNode.ancestorOfHEAD()) {
this.cy(this.aboveNode.cy() + 120);
} else {
this.cy(this.aboveNode.cy() + 60);
}
} else {
this.r(15);
this.cx(610 + 90 * this.branchOrder());
this.cy(this.aboveNode && !isNaN(this.aboveNode.cy()) ? this.aboveNode.cy() + 60 : 120);
}

if (this.aboveNode && this.aboveNode.selected()) {
this.cy(this.aboveNode.cy() + this.aboveNode.commitComponent.element().offsetHeight + 30);
}

this.color(this.ideologicalBranch() ? this.ideologicalBranch().color : '#666');
if (!this.hasBeenRenderedBefore) {
// push this nodes into the graph's node list to be rendered if first time.
// if been pushed before, no need to add to nodes.
this.hasBeenRenderedBefore = true;
graph.nodes.push(this);
}
this.animate();
},
500,
{ leading: true }
);
this.render = _.debounce(this.render.bind(this), 50, { trailing: true });
}

getGraphAttr() {
Expand All @@ -169,6 +133,40 @@ class GitNodeViewModel extends Animateable {
if (parent) parent.belowNode = this;
}

render() {
this.refSearchFormVisible(false);
if (!this.isInited) return;
if (this.ancestorOfHEAD()) {
this.r(30);
this.cx(610);

if (!this.aboveNode) {
this.cy(120);
} else if (this.aboveNode.ancestorOfHEAD()) {
this.cy(this.aboveNode.cy() + 120);
} else {
this.cy(this.aboveNode.cy() + 60);
}
} else {
this.r(15);
this.cx(610 + 90 * this.branchOrder());
this.cy(this.aboveNode && !isNaN(this.aboveNode.cy()) ? this.aboveNode.cy() + 60 : 120);
}

if (this.aboveNode && this.aboveNode.selected()) {
this.cy(this.aboveNode.cy() + this.aboveNode.commitComponent.element().offsetHeight + 30);
}

this.color(this.ideologicalBranch() ? this.ideologicalBranch().color : '#666');
if (!this.hasBeenRenderedBefore) {
// push this nodes into the graph's node list to be rendered if first time.
// if been pushed before, no need to add to nodes.
this.hasBeenRenderedBefore = true;
this.graph.nodes.push(this);
}
this.animate();
}

setData(logEntry) {
this.title(logEntry.message.split('\n')[0]);
this.parents(logEntry.parents || []);
Expand Down
1 change: 1 addition & 0 deletions components/graph/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const _ = require('lodash');
const moment = require('moment');
const octicons = require('octicons');
const components = require('ungit-components');
const programEvents = require('ungit-program-events');
const GitNodeViewModel = require('./git-node');
const GitRefViewModel = require('./git-ref');
const EdgeViewModel = require('./edge');
Expand Down
4 changes: 2 additions & 2 deletions source/git-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ exports.registerApi = (env) => {
return mkdirp(pathToWatch);
})
.then(() => {
const watcher = fs.watch(pathToWatch, options || {}, (event, filename) => {
const watcher = watch(pathToWatch, options || {}, (event, filename) => {
if (event === 'rename' || !filename) return;
const filePath = path.join(subfolderPath, filename);
winston.debug(`File change: ${filePath}`);
Expand Down Expand Up @@ -395,7 +395,7 @@ exports.registerApi = (env) => {
if (err.stderr && err.stderr.indexOf("fatal: bad default revision 'HEAD'") == 0) {
return { limit: limit, skip: skip, nodes: [] };
} else if (
/fatal: your current branch \'.+\' does not have any commits yet.*/.test(err.stderr)
/fatal: your current branch '.+' does not have any commits yet.*/.test(err.stderr)
) {
return { limit: limit, skip: skip, nodes: [] };
} else if (err.stderr && err.stderr.indexOf('fatal: Not a git repository') == 0) {
Expand Down
72 changes: 29 additions & 43 deletions test/spec.git-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,8 @@ describe('git-parser parseGitLog', () => {
timestamp: 1546610046000,
committerEmail: '[email protected]',
committerName: 'Test ungit',
total: {
additions: 176,
deletions: 1,
},
additions: 176,
deletions: 1,
fileLineDiffs: [
{
additions: 1,
Expand Down Expand Up @@ -266,10 +264,8 @@ describe('git-parser parseGitLog', () => {
timestamp: 1546607036000,
committerEmail: '[email protected]',
committerName: 'Test ungit',
total: {
additions: 32,
deletions: 0,
},
additions: 32,
deletions: 0,
fileLineDiffs: [
{
additions: 32,
Expand All @@ -295,10 +291,8 @@ describe('git-parser parseGitLog', () => {
timestamp: 1546606976000,
committerEmail: '[email protected]',
committerName: 'Test ungit',
total: {
additions: 0,
deletions: 0,
},
additions: 0,
deletions: 0,
fileLineDiffs: [],
isHead: false,
message: 'empty commit',
Expand All @@ -315,10 +309,8 @@ describe('git-parser parseGitLog', () => {
timestamp: 1546606916000,
committerEmail: '[email protected]',
committerName: 'Test ungit',
total: {
additions: 14,
deletions: 9,
},
additions: 14,
deletions: 9,
fileLineDiffs: [
{
additions: 4,
Expand Down Expand Up @@ -385,10 +377,8 @@ describe('git-parser parseGitLog', () => {
timestamp: 1546607036000,
committerEmail: '[email protected]',
committerName: 'Test ungit',
total: {
additions: 32,
deletions: 0,
},
additions: 32,
deletions: 0,
fileLineDiffs: [
{
additions: 32,
Expand Down Expand Up @@ -431,10 +421,8 @@ describe('git-parser parseGitLog', () => {
timestamp: 1546607036000,
committerEmail: '[email protected]',
committerName: 'Test ungit',
total: {
additions: 32,
deletions: 0,
},
additions: 32,
deletions: 0,
fileLineDiffs: [
{
additions: 32,
Expand Down Expand Up @@ -518,10 +506,8 @@ describe('git-parser parseGitLog', () => {

expect(gitParser.parseGitLog(gitLog)[0]).to.eql({
refs: ['HEAD', 'refs/heads/git-parser-specs'],
total: {
additions: 32,
deletions: 0,
},
additions: 32,
deletions: 0,
fileLineDiffs: [
{
additions: 32,
Expand Down Expand Up @@ -773,21 +759,21 @@ describe('parseGitStatusNumstat', () => {
describe('parseGitStatus', () => {
it('parses git status', () => {
const gitStatus =
`## git-parser-specs\x00` +
`A file1.js\x00` +
`M file2.js\x00` +
`D file3.js\x00` +
` D file4.js\x00` +
` U file5.js\x00` +
`U file6.js\x00` +
`AA file7.js\x00` +
`? file8.js\x00` +
`A file9.js\x00` +
`?D file10.js\x00` +
`AD file11.js\x00` +
` M file12.js\x00` +
`?? file13.js\x00` +
`R ../source/sys.js\x00../source/sysinfo.js\x00`;
'## git-parser-specs\x00' +
'A file1.js\x00' +
'M file2.js\x00' +
'D file3.js\x00' +
' D file4.js\x00' +
' U file5.js\x00' +
'U file6.js\x00' +
'AA file7.js\x00' +
'? file8.js\x00' +
'A file9.js\x00' +
'?D file10.js\x00' +
'AD file11.js\x00' +
' M file12.js\x00' +
'?? file13.js\x00' +
'R ../source/sys.js\x00../source/sysinfo.js\x00';

expect(gitParser.parseGitStatus(gitStatus)).to.eql({
branch: 'git-parser-specs',
Expand Down

0 comments on commit e9b9fd1

Please sign in to comment.