Skip to content

Commit d704779

Browse files
committed
feat: adding git extension to core, but not loaded for now. working
1 parent 90848fd commit d704779

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+11385
-1
lines changed

src/extensions/default/Git/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
GNU AGPL-3.0 License
2+
3+
Copyright (c) 2021 - present core.ai . All rights reserved.
4+
original work Copyright (c) 2013-2014 Martin Zagora and other contributors
5+
6+
This program is free software: you can redistribute it and/or modify it
7+
under the terms of the GNU Affero General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful, but WITHOUT
12+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
14+
for more details.
15+
16+
You should have received a copy of the GNU Affero General Public License
17+
along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
18+
19+

src/extensions/default/Git/main.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*!
2+
* Brackets Git Extension
3+
*
4+
* @author Martin Zagora
5+
* @license http://opensource.org/licenses/MIT
6+
*/
7+
8+
define(function (require, exports, module) {
9+
10+
// Brackets modules
11+
const _ = brackets.getModule("thirdparty/lodash"),
12+
AppInit = brackets.getModule("utils/AppInit"),
13+
ExtensionUtils = brackets.getModule("utils/ExtensionUtils");
14+
15+
// Local modules
16+
require("src/SettingsDialog");
17+
const EventEmitter = require("src/EventEmitter"),
18+
Events = require("src/Events"),
19+
Main = require("src/Main"),
20+
Preferences = require("src/Preferences"),
21+
BracketsEvents = require("src/BracketsEvents");
22+
23+
// Load extension modules that are not included by core
24+
var modules = [
25+
"src/GutterManager",
26+
"src/History",
27+
"src/NoRepo",
28+
"src/ProjectTreeMarks",
29+
"src/Remotes"
30+
];
31+
require(modules);
32+
33+
// Load CSS
34+
ExtensionUtils.loadStyleSheet(module, "styles/brackets-git.less");
35+
ExtensionUtils.loadStyleSheet(module, "styles/fonts/octicon.less");
36+
37+
AppInit.appReady(function () {
38+
Main.init().then((enabled)=>{
39+
if(!enabled) {
40+
BracketsEvents.disableAll();
41+
}
42+
});
43+
});
44+
45+
// export API's for other extensions
46+
if (typeof window === "object") {
47+
window.phoenixGitEvents = {
48+
EventEmitter: EventEmitter,
49+
Events: Events
50+
};
51+
}
52+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "phcode-git-core",
3+
"title": "Phoenix Code Git",
4+
"version": "1.0.0",
5+
"engines": {
6+
"brackets": ">=4.0.0"
7+
},
8+
"description": "Integration of Git into Phoenix Code",
9+
"dependencies": {}
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
define(function (require, exports, module) {
2+
3+
// Brackets modules
4+
const _ = brackets.getModule("thirdparty/lodash"),
5+
DocumentManager = brackets.getModule("document/DocumentManager"),
6+
FileSystem = brackets.getModule("filesystem/FileSystem"),
7+
ProjectManager = brackets.getModule("project/ProjectManager"),
8+
MainViewManager = brackets.getModule("view/MainViewManager");
9+
10+
// Local modules
11+
const Events = require("src/Events"),
12+
EventEmitter = require("src/EventEmitter"),
13+
HistoryViewer = require("src/HistoryViewer"),
14+
Preferences = require("src/Preferences"),
15+
Utils = require("src/Utils");
16+
17+
// White-list for .git file watching
18+
const watchedInsideGit = ["HEAD"];
19+
const GIT_EVENTS = "gitEvents";
20+
21+
FileSystem.on(`change.${GIT_EVENTS}`, function (evt, file) {
22+
// we care only for files in current project
23+
var currentGitRoot = Preferences.get("currentGitRoot");
24+
if (file && file.fullPath.indexOf(currentGitRoot) === 0) {
25+
26+
if (file.fullPath.indexOf(currentGitRoot + ".git/") === 0) {
27+
28+
var whitelisted = _.any(watchedInsideGit, function (entry) {
29+
return file.fullPath === currentGitRoot + ".git/" + entry;
30+
});
31+
if (!whitelisted) {
32+
Utils.consoleDebug("Ignored FileSystem.change event: " + file.fullPath);
33+
return;
34+
}
35+
36+
}
37+
38+
EventEmitter.emit(Events.BRACKETS_FILE_CHANGED, file);
39+
}
40+
});
41+
42+
DocumentManager.on(`documentSaved.${GIT_EVENTS}`, function (evt, doc) {
43+
// we care only for files in current project
44+
if (doc.file.fullPath.indexOf(Preferences.get("currentGitRoot")) === 0) {
45+
EventEmitter.emit(Events.BRACKETS_DOCUMENT_SAVED, doc);
46+
}
47+
});
48+
49+
MainViewManager.on(`currentFileChange.${GIT_EVENTS}`, function (evt, currentDocument, previousDocument) {
50+
currentDocument = currentDocument || DocumentManager.getCurrentDocument();
51+
if (!HistoryViewer.isVisible()) {
52+
EventEmitter.emit(Events.BRACKETS_CURRENT_DOCUMENT_CHANGE, currentDocument, previousDocument);
53+
} else {
54+
HistoryViewer.hide();
55+
}
56+
});
57+
58+
ProjectManager.on(`projectOpen.${GIT_EVENTS}`, function () {
59+
EventEmitter.emit(Events.BRACKETS_PROJECT_CHANGE);
60+
});
61+
62+
ProjectManager.on(`projectRefresh.${GIT_EVENTS}`, function () {
63+
EventEmitter.emit(Events.BRACKETS_PROJECT_REFRESH);
64+
});
65+
66+
ProjectManager.on(`beforeProjectClose.${GIT_EVENTS}`, function () {
67+
// Disable Git when closing a project so listeners won't fire before new is opened
68+
EventEmitter.emit(Events.GIT_DISABLED);
69+
});
70+
71+
function disableAll() {
72+
FileSystem.off(`change.${GIT_EVENTS}`);
73+
DocumentManager.off(`documentSaved.${GIT_EVENTS}`);
74+
MainViewManager.off(`currentFileChange.${GIT_EVENTS}`);
75+
ProjectManager.off(`projectOpen.${GIT_EVENTS}`);
76+
ProjectManager.off(`projectRefresh.${GIT_EVENTS}`);
77+
ProjectManager.off(`beforeProjectClose.${GIT_EVENTS}`);
78+
}
79+
80+
exports.disableAll = disableAll;
81+
});

0 commit comments

Comments
 (0)