Commit 7a9ce4ff authored by Alain Takoudjou's avatar Alain Takoudjou

Change git repository management UI

parent 577b9352
...@@ -22,6 +22,9 @@ class Popen(subprocess.Popen): ...@@ -22,6 +22,9 @@ class Popen(subprocess.Popen):
def cloneRepo(data): def cloneRepo(data):
workDir = data['path'] workDir = data['path']
if not workDir:
return jsonify(code=0,
result="Can not create project folder: Permission Denied")
code = 0 code = 0
json = "" json = ""
try: try:
...@@ -36,7 +39,7 @@ def cloneRepo(data): ...@@ -36,7 +39,7 @@ def cloneRepo(data):
config_writer.set_value("user", "email", data["email"]) config_writer.set_value("user", "email", data["email"])
code = 1 code = 1
except Exception, e: except Exception, e:
json = str(e) json = safeResult(str(e))
if os.path.exists(workDir): if os.path.exists(workDir):
shutil.rmtree(workDir) shutil.rmtree(workDir)
return jsonify(code=code, result=json) return jsonify(code=code, result=json)
...@@ -52,7 +55,7 @@ def gitStatus(project): ...@@ -52,7 +55,7 @@ def gitStatus(project):
isdirty = repo.is_dirty(untracked_files=True) isdirty = repo.is_dirty(untracked_files=True)
code = 1 code = 1
except Exception, e: except Exception, e:
json = str(e) json = safeResult(str(e))
return jsonify(code=code, result=json, branch=branch, dirty=isdirty) return jsonify(code=code, result=json, branch=branch, dirty=isdirty)
def switchBranch(project, name): def switchBranch(project, name):
...@@ -65,23 +68,26 @@ def switchBranch(project, name): ...@@ -65,23 +68,26 @@ def switchBranch(project, name):
if name == current_branch: if name == current_branch:
json = "This is already your active branch for this project" json = "This is already your active branch for this project"
else: else:
json = "Error: Can not found branch '" + name + "'"
git = repo.git git = repo.git
git.checkout(name) git.checkout(name)
code = 1
except Exception, e: except Exception, e:
json = str(e) json = safeResult(str(e))
return jsonify(code=code, result=json) return jsonify(code=code, result=json)
def createBranch(project, name): def addBranch(project, name, onlyCheckout=False):
code = 0 code = 0
json = "" json = ""
try: try:
repo = Repo(project) repo = Repo(project)
git = repo.git git = repo.git
if not onlyCheckout:
git.checkout('-b', name) git.checkout('-b', name)
else:
git.checkout(name)
code = 1 code = 1
except Exception, e: except Exception, e:
json = str(e) json = safeResult(str(e))
return jsonify(code=code, result=json) return jsonify(code=code, result=json)
def getDiff(project): def getDiff(project):
...@@ -92,7 +98,7 @@ def getDiff(project): ...@@ -92,7 +98,7 @@ def getDiff(project):
current_branch = repo.active_branch.name current_branch = repo.active_branch.name
result = git.diff(current_branch) result = git.diff(current_branch)
except Exception, e: except Exception, e:
result = str(e) result = safeResult(str(e))
return result return result
def gitPush(project, msg): def gitPush(project, msg):
...@@ -120,7 +126,7 @@ def gitPush(project, msg): ...@@ -120,7 +126,7 @@ def gitPush(project, msg):
except Exception, e: except Exception, e:
if undo_commit: if undo_commit:
git.reset("HEAD~") #undo previous commit git.reset("HEAD~") #undo previous commit
json = str(e) json = safeResult(str(e))
return jsonify(code=code, result=json) return jsonify(code=code, result=json)
def gitPull(project): def gitPull(project):
...@@ -133,5 +139,9 @@ def gitPull(project): ...@@ -133,5 +139,9 @@ def gitPull(project):
git.pull() git.pull()
code = 1 code = 1
except Exception, e: except Exception, e:
result = str(e) result = safeResult(str(e))
return jsonify(code=code, result=result) return jsonify(code=code, result=result)
def safeResult(result):
regex=re.compile("(https:\/\/)([\w\d\._-]+:[\w\d\._-]+)\@([\S]+\s)", re.VERBOSE)
return regex.sub(r'\1\3', result)
\ No newline at end of file
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
{% endblock %} {% endblock %}
{% block body %} {% block body %}
<div id="repository"> <h2 class='title'>Clone your repository into the workspace</h2><br/>
<h2>Clone your repository into the workspace</h2><br/> <div id="repository" style="margin-left:40px;">
<label for='name'>Project name*: </label> <label for='name'>Project name*: </label>
<input type="text" name="name" id="name" size='20' value="Enter the project name..." /> <input type="text" name="name" id="name" size='20' value="Enter the project name..." />
<label for='repo'>&nbsp;url: &nbsp;&nbsp;&nbsp;</label> <label for='repo'>&nbsp;url*: &nbsp;&nbsp;</label>
<input type="text" name="repo" id="repo" size='25' value="Enter the url of your repository..." /><br/> <input type="text" name="repo" id="repo" size='25' value="Enter the url of your repository..." /><br/>
<label for='user'>Your name: &nbsp;&nbsp;&nbsp;&nbsp;</label> <label for='user'>Your name: &nbsp;&nbsp;&nbsp;&nbsp;</label>
<input type="text" name="user" id="user" size='20' value="Enter your name..." /> <input type="text" name="user" id="user" size='20' value="Enter your name..." />
...@@ -21,16 +21,46 @@ ...@@ -21,16 +21,46 @@
<input type="hidden" name="workdir" id="workdir" value="{{workDir}}" /> <input type="hidden" name="workdir" id="workdir" value="{{workDir}}" />
<button class="button" id="clone">clone</button> <button class="button" id="clone">clone</button>
<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="" />
<br/><br/><br/> <br/><br/>
</div> </div>
<h2>You can use this public key for Git SSH</h2> <h2>Set your Security Mode</h2>
<textarea class="public_key" readonly> <div class="clone-box-right">
{{public_key}} <div style="background:#fff; padding:10px; min-height:100px; font-size:14px;">
</textarea> <div id="box0">
<p>to use git with https, please enter your repository url like this <h2>Clone Repository without using HTTPS and SSH</h2><br/>
<strong><i>https://your_login:your_password@your_repository</i></strong></p><br/><br/> <p>Choose this mode if you have login and password for the repository and you if you don't have the possibility to
use SSH authentication. Otherwise use your public key or your login and password to clone your project. Note
that, with readonly mode you can not be able to push your changes.</p>
<br/>
</div>
<div id="box1" style="display:none">
<h2>You can use this public key to setup your repository</h2><br/>
<textarea class="public_key" readonly>
{{public_key}}
</textarea>
</div>
<div id="box2" style="display:none;">
<h2>Enter your username and password for https authentication access</h2><br/>
<div style="margin-left:80px; margin-bottom:20px;">
<label for='username'>Your username:&nbsp;&nbsp;</label>
<input type="text" name="username" id="username" size='20' value="Enter your username..." /><br/><br/>
<label for='password'>Your password: &nbsp;&nbsp;</label>
<input type="password" name="password" id="password" size='20' value="" class="idleField" />
</div>
<p></p>
</div>
</div>
</div>
<div class="clone-box-left">
<ul id="modelist">
<li class="checked"><input type="radio" name="security" id="nothing" value="nothing" /><label for="nothing">ReadOnly</label></li>
<li><input type="radio" name="security" id="ssh" value="SSH" checked /><label for="ssh">SSH Mode</label></li>
<li><input type="radio" name="security" id="https" value="HTTPS" /><label for="https">Https Mode</label></li>
</ul>
</div>
<div class="clear"></div><br/>
<div id="file_navigation"> <div id="file_navigation">
<h2>Your project folder</h2> <h2 class='title'>Your project folder</h2><br/>
<div id="fileTree" class="file_tree"></div> <div id="fileTree" class="file_tree"></div>
</div> </div>
{% endblock %} {% endblock %}
...@@ -33,6 +33,11 @@ ...@@ -33,6 +33,11 @@
&nbsp;&nbsp;<label for='branchname'>Branch Name: </label> &nbsp;&nbsp;<label for='branchname'>Branch Name: </label>
<input type="text" name="branchname" id="branchname" size='22' value="Enter the branch name..." /> <input type="text" name="branchname" id="branchname" size='22' value="Enter the branch name..." />
<input type="submit" name="addbranch" id ="addbranch" value="Add" class="button"/> <input type="submit" name="addbranch" id ="addbranch" value="Add" class="button"/>
<div style="margin-left:166px;">
<label for='checkout'>Checkout existing branch: </label>
<input type="text" name="checkout" id="checkout" size='22' value="Existing branch name..." />
<input type="submit" name="docheckout" id ="docheckout" value="Checkout" class="button"/>
</div>
<br/> <br/>
<!--<label for='pullbranch'>Update your local repository: </label>--> <!--<label for='pullbranch'>Update your local repository: </label>-->
<!--<input type="submit" name="pullbranch" id ="pullbranch" value="Pull" class="button"/>--> <!--<input type="submit" name="pullbranch" id ="pullbranch" value="Pull" class="button"/>-->
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
{% block body %} {% block body %}
<form action="{{ url_for('manageProject') }}" method=get> <form action="{{ url_for('manageProject') }}" method=get>
<dl> <dl>
<dd><h2>Diff file for "{{project}}"</h2></dd> <dd><h2 class='title'>Diff file for "{{project}}"</h2></dd>
<dd> <dd>
<div class="main_content"> <div class="main_content">
<pre id="editor"> <pre id="editor">
......
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