Commit 23c574f4 authored by Nicolas Wavrant's avatar Nicolas Wavrant

slaprunner : separation of commit and push

parent d2f691ec
......@@ -117,35 +117,40 @@ def getDiff(project):
result = safeResult(str(e))
return result
def gitPush(project, msg):
"""Commit and Push changes for the specified repository
def gitCommit(project, msg):
"""Commit changes for the specified repository
Args:
project: directory of the local repository
msg: commit message"""
code = 0
json = ""
undo_commit = False
try:
repo = Repo(project)
if repo.is_dirty:
git = repo.git
current_branch = repo.active_branch.name
#add file to be commited
files = repo.untracked_files
for f in files:
git.add(f)
#Commit all modified and untracked files
git.commit('-a', '-m', msg)
undo_commit = True
#push changes to repo
git.push('origin', current_branch)
code = 1
else:
code = 1
json = "Nothing to be commited"
return jsonify(code=code, result=json)
def gitPush(project):
"""Push changes for the specified repository
Args:
project: directory of the local repository
msg: commit message"""
code = 0
json = ""
try:
#push changes to repo
current_branch = repo.active_branch.name
git.push('origin', current_branch)
code = 1
except Exception as e:
if undo_commit:
git.reset("HEAD~") #undo previous commit
json = safeResult(str(e))
return jsonify(code=code, result=json)
......
......@@ -23,6 +23,7 @@ $(document).ready(function () {
urldata = $("input#workdir").val() + "/" + project;
$("#status").empty();
$("#commit").hide();
$("#push").hide();
$("#flash").empty();
if (project === "") {
......@@ -45,6 +46,7 @@ $(document).ready(function () {
//alert(message);
$("#status").append("<p>" + message + "</p>");
if (data.dirty) {
$("#commit").show();
$("#push").show();
$("#status").append("<br/><h2>Display Diff for current Project</h2>");
$("#status").append("<p style='font-size:15px;'>You have changes in your project." +
......@@ -131,11 +133,11 @@ $(document).ready(function () {
send = true;
var project = $("#project").val();
$("#imgwaitting").fadeIn('normal');
$("#commit").empty();
//$("#commit").empty();
$("#commit").attr("value", "Wait...");
$.ajax({
type: "POST",
url: $SCRIPT_ROOT + '/pushProjectFiles',
url: $SCRIPT_ROOT + '/commitProjectFiles',
data: {project: $("input#workdir").val() + "/" + project, msg: $("input#commitmsg").val()},
success: function (data) {
if (data.code === 1) {
......@@ -156,7 +158,33 @@ $(document).ready(function () {
});
return false;
});
$("#push").click(function() {
if (send) {
return false;
}
send = true;
var project = $("#project").val();
$.ajax({
type: "POST",
url: $SCRIPT_ROOT + '/pushProjectFiles',
data: {project: $("input#workdir").val() + "/" + project};
success: function(data) {
if (data.code === 1) {
if (data.result !== "") {
$("#error").Popup(data.result, {type: 'error', duration: 5000});
} else {
$("#error").Popup("The local commits have correctly been saved on the server", {type: 'confirm', duration: 3000});
}
gitStatus();
} else {
$("#error").Popup(data.result, {type: 'error'});
}
$("#push").hide();
send = false;
}
});
return false;
)};
/*
$("#pullbranch").click(function (){
if (send){
......
......@@ -66,7 +66,7 @@
</div>
<div class="wmenu">
<ul>
<li><a href="{{ url_for('editSoftwareProfile') }}">Profiles 3</a></li>
<li><a href="{{ url_for('editSoftwareProfile') }}">Profiles 4</a></li>
<li><a href="{{ url_for('browseWorkspace') }}">Workspace</a></li>
<li class='sep'></li>
<li><a href="{{ url_for('runSoftwareProfile') }}" id="softrun">Run software</a></li>
......
......@@ -40,7 +40,7 @@
<!--<img class="waitting" id="pullimgwaitting" src="{{ url_for('static', filename='images/waiting.gif') }}" alt="" />-->
</div>
</div>
<div id="push" style="margin-bottom:20px;">
<div id="commit" style="margin-bottom:20px;">
<h2>Commit All your changes (On active branch)</h2>
<div style="margin-left:15px;">
<label for='commitmsg'>Commit message: </label>
......@@ -49,6 +49,12 @@
<img class="waitting" id="imgwaitting" src="{{ url_for('static', filename='images/waiting.gif') }}" alt="" />
</div>
</div>
<div id="push" style="margin-bottom:20px;">
<h2>Push your Last Commits</h2>
<div style="margin-left:15px;">
<input type="submit" name="push" id="push" value="Push" class="button"/>
</div>
</div>
<br/>
</div>
</div>
......
......@@ -28,7 +28,7 @@ from slapos.runner.utils import (checkSoftwareFolder, configNewSR, getFolder,
from slapos.runner.fileBrowser import FileBrowser
from slapos.runner.gittools import (cloneRepo, gitStatus, switchBranch,
addBranch, getDiff, gitPush, gitPull)
addBranch, getDiff, gitCommit, gitPush, gitPull)
app = Flask(__name__)
......@@ -389,12 +389,20 @@ def getProjectDiff(project):
path = os.path.join(app.config['workspace'], project)
return render_template('projectDiff.html', project=project,
diff=getDiff(path))
@login_required()
def commitProjectFiles():
#import pdb; pdb.set_trace()
path = realpath(app.config, request.form['project'])
if path:
return gitCommit(path, request.form['msg'])
else:
return jsonify(code=0, result="Can not read folder: Permission Denied")
@login_required()
def pushProjectFiles():
path = realpath(app.config, request.form['project'])
if path:
return gitPush(path, request.form['msg'])
return gitPush(path)
else:
return jsonify(code=0, result="Can not read folder: Permission Denied")
......@@ -673,6 +681,8 @@ app.add_url_rule("/checkFileType", 'checkFileType', checkFileType,
methods=['POST'])
app.add_url_rule("/pullProjectFiles", 'pullProjectFiles', pullProjectFiles,
methods=['POST'])
app.add_url_rule("/commitProjectFiles", 'commitProjectFiles', commitProjectFiles,
methods=['POST'])
app.add_url_rule("/pushProjectFiles", 'pushProjectFiles', pushProjectFiles,
methods=['POST'])
app.add_url_rule("/getProjectDiff/<project>", 'getProjectDiff', getProjectDiff,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment