Skip to content

Commit

Permalink
Adding 'deleting interfering uncommitted files' function to the updat…
Browse files Browse the repository at this point in the history
…e app
  • Loading branch information
CRImier committed Jun 1, 2018
1 parent 3d1d9fa commit fc217f1
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions apps/settings/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import signal
from subprocess import check_output
from subprocess import check_output, STDOUT, CalledProcessError
from time import sleep

try:
Expand Down Expand Up @@ -32,7 +32,7 @@ def git_available(cls):
def command(command):
commandline = "git {}".format(command)
logger.debug("Executing: {}".format(commandline))
return check_output(commandline, shell=True)
return check_output(commandline, shell=True, stderr=STDOUT)

@classmethod
def get_head_for_branch(cls, branch):
Expand All @@ -49,7 +49,24 @@ def checkout(cls, reference):

@classmethod
def pull(cls, source = "origin", branch = "master", opts="--no-edit"):
return cls.command("pull {2} {0} {1}".format(source, branch, opts))
try:
return cls.command("pull {2} {0} {1}".format(source, branch, opts))
except CalledProcessError as e:
lines = iter(e.output.split('\n'))
for line in lines:
marker = "following untracked working tree files would be overwritten by merge"
if marker in line:
line = next(lines)
while line.startswith('\t'):
line = line.strip()
if not line.endswith('/'):
try:
logger.info("Removing interfering file: {}".format(line))
os.remove(line)
except OSError:
logger.warning("Couldn't remove an interfering file {} while pulling!".format(line))
line = next(lines)
return cls.command("pull {2} {0} {1}".format(source, branch, opts))


class UpdateUnnecessary(Exception):
Expand Down

0 comments on commit fc217f1

Please sign in to comment.