Skip to content

Commit 91af462

Browse files
committed
bug fix: add path to git commands
1 parent bf255dc commit 91af462

File tree

5 files changed

+134
-4
lines changed

5 files changed

+134
-4
lines changed

websiteFunctions/static/websiteFunctions/websiteFunctions.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5825,6 +5825,7 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
58255825
$scope.gitEnable = false;
58265826
$scope.branches = response.data.finalBranches;
58275827
$scope.deploymentKey = response.data.deploymentKey;
5828+
$scope.remote = response.data.remote;
58285829
} else {
58295830
$scope.gitTracking = false;
58305831
$scope.gitEnable = true;
@@ -5853,6 +5854,61 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
58535854

58545855
};
58555856

5857+
$scope.initRepo = function () {
5858+
5859+
$scope.cyberpanelLoading = false;
5860+
5861+
url = "/websites/initRepo";
5862+
5863+
5864+
var data = {
5865+
domain: $("#domain").text(),
5866+
folder: $scope.folder
5867+
5868+
};
5869+
5870+
var config = {
5871+
headers: {
5872+
'X-CSRFToken': getCookie('csrftoken')
5873+
}
5874+
};
5875+
5876+
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
5877+
5878+
function ListInitialDatas(response) {
5879+
$scope.cyberpanelLoading = true;
5880+
5881+
if (response.data.status === 1) {
5882+
new PNotify({
5883+
title: 'Success',
5884+
text: 'Repo initiated.',
5885+
type: 'success'
5886+
});
5887+
$scope.fetchFolderDetails();
5888+
} else {
5889+
new PNotify({
5890+
title: 'Operation Failed!',
5891+
text: response.data.error_message,
5892+
type: 'error'
5893+
});
5894+
}
5895+
5896+
5897+
}
5898+
5899+
function cantLoadInitialDatas(response) {
5900+
$scope.cyberpanelLoading = true;
5901+
new PNotify({
5902+
title: 'Operation Failed!',
5903+
text: 'Could not connect to server, please refresh this page.',
5904+
type: 'error'
5905+
});
5906+
5907+
5908+
}
5909+
5910+
};
5911+
58565912
function getCreationStatus() {
58575913

58585914
url = "/websites/installWordpressStatus";

websiteFunctions/templates/websiteFunctions/manageGIT.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,20 @@ <h3 class="title-hero">
8585
<select ng-change="fetchFolderDetails()" ng-model="branchName" class="form-control">
8686
<option ng-repeat="branch in branches track by $index">{$ branch $}</option>
8787
</select></td>
88-
<td></td>
88+
<td>
89+
<button ng-hide="remote==1" style="margin-left: 2%" type="button"
90+
class="btn btn-primary"
91+
ng-click="initRepo()">
92+
Setup Remote
93+
</button>
94+
95+
<button ng-hide="remote==0" style="margin-left: 2%" type="button"
96+
class="btn btn-primary"
97+
ng-click="initRepo()">
98+
View Remote
99+
</button>
100+
101+
</td>
89102
<td></td>
90103
<td></td>
91104
</tr>

websiteFunctions/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121

122122
url(r'^(?P<domain>(.*))/manageGIT$', views.manageGIT, name='manageGIT'),
123123
url(r'^fetchFolderDetails$', views.fetchFolderDetails, name='fetchFolderDetails'),
124+
url(r'^initRepo$', views.initRepo, name='initRepo'),
124125

125126
## Catch all for domains
126127
url(r'^(?P<domain>(.*))/(?P<childDomain>(.*))$', views.launchChild, name='launchChild'),

websiteFunctions/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,5 +731,13 @@ def fetchFolderDetails(request):
731731
userID = request.session['userID']
732732
wm = WebsiteManager()
733733
return wm.fetchFolderDetails(userID, json.loads(request.body))
734+
except KeyError:
735+
return redirect(loadLoginPage)
736+
737+
def initRepo(request):
738+
try:
739+
userID = request.session['userID']
740+
wm = WebsiteManager()
741+
return wm.initRepo(userID, json.loads(request.body))
734742
except KeyError:
735743
return redirect(loadLoginPage)

websiteFunctions/website.py

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,8 +2947,8 @@ def fetchFolderDetails(self, userID=None, data=None):
29472947

29482948
## Find git branches
29492949

2950-
command = 'git --git-dir=%s/.git branch' % (self.folder)
2951-
branches = ProcessUtilities.outputExecutioner(command).split('\n')
2950+
command = 'git -C %s branch' % (self.folder)
2951+
branches = ProcessUtilities.outputExecutioner(command).split('\n')[:-1]
29522952

29532953
## Fetch key
29542954

@@ -2975,7 +2975,59 @@ def fetchFolderDetails(self, userID=None, data=None):
29752975
command = 'cat /home/%s/.ssh/%s.pub' % (self.domain, website.externalApp)
29762976
deploymentKey = ProcessUtilities.outputExecutioner(command, website.externalApp)
29772977

2978-
data_ret = {'status': 1, 'repo': 1, 'finalBranches': branches, 'deploymentKey': deploymentKey}
2978+
if deploymentKey.find('No such file or directory') > -1:
2979+
command = "ssh-keygen -f /home/%s/.ssh/%s -t rsa -N ''" % (self.domain, website.externalApp)
2980+
ProcessUtilities.executioner(command, website.externalApp)
2981+
2982+
command = 'cat /home/%s/.ssh/%s.pub' % (self.domain, website.externalApp)
2983+
deploymentKey = ProcessUtilities.outputExecutioner(command, website.externalApp)
2984+
2985+
## Find Remote if any
2986+
2987+
command = 'git -C %s remote -v' % (self.folder)
2988+
remoteResult = ProcessUtilities.outputExecutioner(command)
2989+
2990+
remote = 1
2991+
if remoteResult.find('origin') == -1:
2992+
remote = 0
2993+
2994+
data_ret = {'status': 1, 'repo': 1, 'finalBranches': branches, 'deploymentKey': deploymentKey, 'remote': remote, 'remoteResult': remoteResult}
2995+
json_data = json.dumps(data_ret)
2996+
return HttpResponse(json_data)
2997+
2998+
except BaseException as msg:
2999+
data_ret = {'status': 0, 'installStatus': 0, 'error_message': str(msg)}
3000+
json_data = json.dumps(data_ret)
3001+
return HttpResponse(json_data)
3002+
3003+
def initRepo(self, userID=None, data=None):
3004+
try:
3005+
3006+
currentACL = ACLManager.loadedACL(userID)
3007+
admin = Administrator.objects.get(pk=userID)
3008+
3009+
self.domain = data['domain']
3010+
self.folder = data['folder']
3011+
3012+
if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
3013+
pass
3014+
else:
3015+
return ACLManager.loadErrorJson('status', 0)
3016+
3017+
if self.folderCheck():
3018+
pass
3019+
else:
3020+
return ACLManager.loadErrorJson()
3021+
3022+
command = 'git -C %s init' % (self.folder)
3023+
result = ProcessUtilities.outputExecutioner(command)
3024+
3025+
if result.find('Initialized empty Git repository in') > -1:
3026+
data_ret = {'status': 1}
3027+
json_data = json.dumps(data_ret)
3028+
return HttpResponse(json_data)
3029+
else:
3030+
data_ret = {'status': 0, 'error_message': result}
29793031
json_data = json.dumps(data_ret)
29803032
return HttpResponse(json_data)
29813033

0 commit comments

Comments
 (0)