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): ...@@ -117,35 +117,40 @@ def getDiff(project):
result = safeResult(str(e)) result = safeResult(str(e))
return result return result
def gitPush(project, msg): def gitCommit(project, msg):
"""Commit and Push changes for the specified repository """Commit changes for the specified repository
Args:
project: directory of the local repository
msg: commit message"""
code = 0
json = ""
repo = Repo(project)
if repo.is_dirty:
git = repo.git
#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)
else:
code = 1
json = "Nothing to be commited"
return jsonify(code=code, result=json)
def gitPush(project):
"""Push changes for the specified repository
Args: Args:
project: directory of the local repository project: directory of the local repository
msg: commit message""" msg: commit message"""
code = 0 code = 0
json = "" json = ""
undo_commit = False
try: try:
repo = Repo(project) #push changes to repo
if repo.is_dirty: current_branch = repo.active_branch.name
git = repo.git git.push('origin', current_branch)
current_branch = repo.active_branch.name code = 1
#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:
json = "Nothing to be commited"
code = 1
except Exception as e: except Exception as e:
if undo_commit:
git.reset("HEAD~") #undo previous commit
json = safeResult(str(e)) json = safeResult(str(e))
return jsonify(code=code, result=json) return jsonify(code=code, result=json)
......
...@@ -23,6 +23,7 @@ $(document).ready(function () { ...@@ -23,6 +23,7 @@ $(document).ready(function () {
urldata = $("input#workdir").val() + "/" + project; urldata = $("input#workdir").val() + "/" + project;
$("#status").empty(); $("#status").empty();
$("#commit").hide();
$("#push").hide(); $("#push").hide();
$("#flash").empty(); $("#flash").empty();
if (project === "") { if (project === "") {
...@@ -45,7 +46,8 @@ $(document).ready(function () { ...@@ -45,7 +46,8 @@ $(document).ready(function () {
//alert(message); //alert(message);
$("#status").append("<p>" + message + "</p>"); $("#status").append("<p>" + message + "</p>");
if (data.dirty) { if (data.dirty) {
$("#push").show(); $("#commit").show();
$("#push").show();
$("#status").append("<br/><h2>Display Diff for current Project</h2>"); $("#status").append("<br/><h2>Display Diff for current Project</h2>");
$("#status").append("<p style='font-size:15px;'>You have changes in your project." + $("#status").append("<p style='font-size:15px;'>You have changes in your project." +
" <a href='" + $SCRIPT_ROOT + "/getProjectDiff/" " <a href='" + $SCRIPT_ROOT + "/getProjectDiff/"
...@@ -131,11 +133,11 @@ $(document).ready(function () { ...@@ -131,11 +133,11 @@ $(document).ready(function () {
send = true; send = true;
var project = $("#project").val(); var project = $("#project").val();
$("#imgwaitting").fadeIn('normal'); $("#imgwaitting").fadeIn('normal');
$("#commit").empty(); //$("#commit").empty();
$("#commit").attr("value", "Wait..."); $("#commit").attr("value", "Wait...");
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: $SCRIPT_ROOT + '/pushProjectFiles', url: $SCRIPT_ROOT + '/commitProjectFiles',
data: {project: $("input#workdir").val() + "/" + project, msg: $("input#commitmsg").val()}, data: {project: $("input#workdir").val() + "/" + project, msg: $("input#commitmsg").val()},
success: function (data) { success: function (data) {
if (data.code === 1) { if (data.code === 1) {
...@@ -156,7 +158,33 @@ $(document).ready(function () { ...@@ -156,7 +158,33 @@ $(document).ready(function () {
}); });
return false; 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 (){ $("#pullbranch").click(function (){
if (send){ if (send){
......
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
</div> </div>
<div class="wmenu"> <div class="wmenu">
<ul> <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><a href="{{ url_for('browseWorkspace') }}">Workspace</a></li>
<li class='sep'></li> <li class='sep'></li>
<li><a href="{{ url_for('runSoftwareProfile') }}" id="softrun">Run software</a></li> <li><a href="{{ url_for('runSoftwareProfile') }}" id="softrun">Run software</a></li>
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
<!--<img class="waitting" id="pullimgwaitting" src="{{ url_for('static', filename='images/waiting.gif') }}" alt="" />--> <!--<img class="waitting" id="pullimgwaitting" src="{{ url_for('static', filename='images/waiting.gif') }}" alt="" />-->
</div> </div>
</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> <h2>Commit All your changes (On active branch)</h2>
<div style="margin-left:15px;"> <div style="margin-left:15px;">
<label for='commitmsg'>Commit message: </label> <label for='commitmsg'>Commit message: </label>
...@@ -49,6 +49,12 @@ ...@@ -49,6 +49,12 @@
<img class="waitting" id="imgwaitting" src="{{ url_for('static', filename='images/waiting.gif') }}" alt="" /> <img class="waitting" id="imgwaitting" src="{{ url_for('static', filename='images/waiting.gif') }}" alt="" />
</div> </div>
</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/> <br/>
</div> </div>
</div> </div>
......
...@@ -28,7 +28,7 @@ from slapos.runner.utils import (checkSoftwareFolder, configNewSR, getFolder, ...@@ -28,7 +28,7 @@ from slapos.runner.utils import (checkSoftwareFolder, configNewSR, getFolder,
from slapos.runner.fileBrowser import FileBrowser from slapos.runner.fileBrowser import FileBrowser
from slapos.runner.gittools import (cloneRepo, gitStatus, switchBranch, from slapos.runner.gittools import (cloneRepo, gitStatus, switchBranch,
addBranch, getDiff, gitPush, gitPull) addBranch, getDiff, gitCommit, gitPush, gitPull)
app = Flask(__name__) app = Flask(__name__)
...@@ -389,12 +389,20 @@ def getProjectDiff(project): ...@@ -389,12 +389,20 @@ def getProjectDiff(project):
path = os.path.join(app.config['workspace'], project) path = os.path.join(app.config['workspace'], project)
return render_template('projectDiff.html', project=project, return render_template('projectDiff.html', project=project,
diff=getDiff(path)) 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() @login_required()
def pushProjectFiles(): def pushProjectFiles():
path = realpath(app.config, request.form['project']) path = realpath(app.config, request.form['project'])
if path: if path:
return gitPush(path, request.form['msg']) return gitPush(path)
else: else:
return jsonify(code=0, result="Can not read folder: Permission Denied") return jsonify(code=0, result="Can not read folder: Permission Denied")
...@@ -673,6 +681,8 @@ app.add_url_rule("/checkFileType", 'checkFileType', checkFileType, ...@@ -673,6 +681,8 @@ app.add_url_rule("/checkFileType", 'checkFileType', checkFileType,
methods=['POST']) methods=['POST'])
app.add_url_rule("/pullProjectFiles", 'pullProjectFiles', pullProjectFiles, app.add_url_rule("/pullProjectFiles", 'pullProjectFiles', pullProjectFiles,
methods=['POST']) methods=['POST'])
app.add_url_rule("/commitProjectFiles", 'commitProjectFiles', commitProjectFiles,
methods=['POST'])
app.add_url_rule("/pushProjectFiles", 'pushProjectFiles', pushProjectFiles, app.add_url_rule("/pushProjectFiles", 'pushProjectFiles', pushProjectFiles,
methods=['POST']) methods=['POST'])
app.add_url_rule("/getProjectDiff/<project>", 'getProjectDiff', getProjectDiff, 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