Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD sidecar API support to (force) push changes without committing. #389

Merged
merged 2 commits into from
Sep 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 37 additions & 24 deletions theia/sidecar/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def index():
# Get options from the form
repo: str = request.form.get('repo', default=None)
message: str = request.form.get('message', default='Anubis Cloud IDE Autosave').strip()
push_only: bool = request.form.get('push_only', default='false').lower() == 'true'
force_push: bool = request.form.get('force_push', default='false').lower() == 'true'

# Default commit message if empty
if message == '':
Expand All @@ -45,45 +47,56 @@ def index():
if repo is None or not os.path.isdir(os.path.join(repo, '.git')):
return text_response('Please navigate to the repository that you would like to autosave')

try:
# Add
add = subprocess.run(
['git', '-c', 'core.hooksPath=/dev/null', '-c', 'alias.push=push', 'add', '.'],
cwd=repo,
timeout=3,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
if add.returncode != 0:
return text_response('Failed to git add')
output: list[bytes] = []

# Commit
commit = subprocess.run(
['git', '-c', 'core.hooksPath=/dev/null', '-c', 'alias.commit=commit', 'commit', '--no-verify', '-m', message],
cwd=repo,
timeout=3,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
if commit.returncode != 0:
return text_response('Failed to git commit')
try:
# We skip the add and commit phase if push_only is enabled
# In that case, we will only try to push
if not push_only:
# Add
add = subprocess.run(
['git', '-c', 'core.hooksPath=/dev/null', '-c', 'alias.push=push', 'add', '.'],
cwd=repo,
timeout=3,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
if add.returncode != 0:
return text_response('Failed to git add')
output.append(add.stdout)

# Commit
commit = subprocess.run(
['git', '-c', 'core.hooksPath=/dev/null', '-c', 'alias.commit=commit', 'commit', '--no-verify', '-m', message],
cwd=repo,
timeout=3,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
if commit.returncode != 0:
return text_response('Failed to git commit')
output.append(commit.stdout)

# Push
push_args = ['git', '-c', 'core.hooksPath=/dev/null', '-c', 'alias.push=push', 'push', '--no-verify']
if force_push:
push_args.append('--force')
push = subprocess.run(
['git', '-c', 'core.hooksPath=/dev/null', '-c', 'alias.push=push', 'push', '--no-verify'],
push_args,
cwd=repo,
timeout=3,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
if push.returncode != 0:
return text_response('Failed to git push')
output.append(push.stdout)

except subprocess.TimeoutExpired:
return text_response('Autosave timeout')

output = (add.stdout + commit.stdout + push.stdout + b'\n').decode()
return text_response(output)
output.append(b'\n')
return text_response(b"".join(output).decode())


if ADMIN:
Expand Down