Skip to content
Merged
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src-node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/extensions/default/Git/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ define(function (require, exports, module) {
"src/History",
"src/NoRepo",
"src/ProjectTreeMarks",
"src/Remotes"
"src/Remotes",
"src/TabBarIntegration"
];
require(modules);

Expand All @@ -48,10 +49,12 @@ define(function (require, exports, module) {

// export API's for other extensions
if (typeof window === "object") {
const TabBarIntegration = require("src/TabBarIntegration");
window.phoenixGitEvents = {
EventEmitter: EventEmitter,
Events: Events,
Git
Git,
TabBarIntegration
};
}
});
90 changes: 90 additions & 0 deletions src/extensions/default/Git/src/TabBarIntegration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
define(function (require) {
const EventEmitter = require("src/EventEmitter");
const Events = require("src/Events");
const Git = require("src/git/Git");
const Preferences = require("src/Preferences");

// the cache of file statuses by path
let fileStatusCache = {};

/**
* this function is responsible to get the Git status for a file path
*
* @param {string} fullPath - the file path
* @returns {Array|null} - Array of status strings or null if no status
*/
function getFileStatus(fullPath) {
return fileStatusCache[fullPath] || null;
}

/**
* whether the file is modified or not
*
* @param {string} fullPath - the file path
* @returns {boolean} - True if the file is modified otherwise false
*/
function isModified(fullPath) {
const status = getFileStatus(fullPath);
if (!status) {
return false;
}
return status.some(
(statusType) =>
statusType === Git.FILE_STATUS.MODIFIED ||
statusType === Git.FILE_STATUS.RENAMED ||
statusType === Git.FILE_STATUS.COPIED
);
}

/**
* whether the file is untracked or not
*
* @param {string} fullPath - the file path
* @returns {boolean} - True if the file is untracked otherwise false
*/
function isUntracked(fullPath) {
const status = getFileStatus(fullPath);
if (!status) {
return false;
}

// return true if it's untracked or if it's newly added (which means it was untracked before staging)
return (
status.includes(Git.FILE_STATUS.UNTRACKED) ||
(status.includes(Git.FILE_STATUS.ADDED) && status.includes(Git.FILE_STATUS.STAGED))
);
}


// Update file status cache when Git status results are received
EventEmitter.on(Events.GIT_STATUS_RESULTS, function (files) {
// reset the cache
fileStatusCache = {};

const gitRoot = Preferences.get("currentGitRoot");
if (!gitRoot) {
return;
}

// we need to update cache with new status results
files.forEach(function (entry) {
const fullPath = gitRoot + entry.file;
fileStatusCache[fullPath] = entry.status;
});

// notify that file statuses have been updated
EventEmitter.emit("GIT_FILE_STATUS_CHANGED", fileStatusCache);
});

// clear cache when Git is disabled
EventEmitter.on(Events.GIT_DISABLED, function () {
fileStatusCache = {};
EventEmitter.emit("GIT_FILE_STATUS_CHANGED", fileStatusCache);
});

return {
getFileStatus: getFileStatus,
isModified: isModified,
isUntracked: isUntracked
};
});
Loading
Loading