Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Bug fixes and improvements #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions svn-stash.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def execute_stash_push(target_file,filename_list):
if len(filename_list)>0:
#save the svn status into a stash
stash = svn_stash()
stash.push(target_file,filename_list)
stash.push(target_file,filename_list)
register = svn_stash_register()
register.register_stash(stash)
register.write()
Expand Down Expand Up @@ -60,7 +60,7 @@ def execute_stash_show(target_file,filename_list):
for stash_id in register.stashes:
current_stash = svn_stash()
current_stash.load(stash_id)
print current_stash
print current_stash

def execute_stash_help(target_file,filename_list):
b = "\033[1m"
Expand Down Expand Up @@ -98,7 +98,7 @@ def execute_svn_stash(command,target_file,filename_list):

#obtain the svn status files
def obtain_svn_status_files():
status_files = []
status_files = []
status_list = os.popen('svn st').read()
status_list = status_list.split("\n")
for line in status_list:
Expand All @@ -115,11 +115,11 @@ def main(args):
command = COMMAND_DEFAULT
if len(args)>1:
command = args[1]

target_file = TARGET_FILE_DEFAULT
if len(args)>2:
target_file = args[2]

filename_list = obtain_svn_status_files()
execute_svn_stash(command,target_file,filename_list)

Expand Down
39 changes: 25 additions & 14 deletions svn_stash_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def write(self):
f.writelines(content)
f.close()
except IOError as e:
print 'registerFile cannot be created.'
print 'registerFile cannot be created.'

def obtain_last_stash(self):
length = len(self.stashes)
Expand Down Expand Up @@ -112,12 +112,14 @@ def pop(self):
result = ""
if os.path.exists(SVN_STASH_DIR):
for target_file in self.files:
randkey = self.files[target_file]
result = os.popen("patch -p0 < " + SVN_STASH_DIR + "/" + str(randkey) + ".stash.patch").read()
result += os.popen("rm " + SVN_STASH_DIR + "/" + str(randkey) + ".stash.patch").read()
#print "pop " + target_file
#delete the file of svn_stash
result += os.popen("rm " + SVN_STASH_DIR + "/" + str(self.key)).read()
randkey = self.files[target_file]
filepath = SVN_STASH_DIR + "/" + str(randkey) + ".stash.patch"

if os.path.isfile(filepath):
result = os.popen("svn patch " + filepath).read()
#print "pop " + target_file
else:
print 'Patch file cannot be found.'

def write(self):
#Create file for svn stash
Expand All @@ -137,12 +139,21 @@ def write(self):
print 'randFile cannot be created.'

def clear(self):
result = ""
result = ""
if os.path.exists(SVN_STASH_DIR):
for target_file in self.files:
randkey = self.files[target_file]
result += os.popen("rm " + SVN_STASH_DIR + "/" + str(randkey) + ".stash.patch").read()
result += os.popen("rm " + SVN_STASH_DIR + "/" + str(self.key)).read()
for target_file in self.files:
randkey = self.files[target_file]
filepath = SVN_STASH_DIR + "/" + str(randkey) + ".stash.patch"
if os.path.isfile(filepath):
result += os.popen("rm " + filepath).read()
else:
print 'randFile cannot be found.'

filepath = SVN_STASH_DIR + "/" + str(self.key)
if os.path.isfile(filepath):
result += os.popen("rm " + filepath).read()
else:
print 'registerFile cannot be found.'

def load(self,stash_id):
try:
Expand Down Expand Up @@ -173,7 +184,7 @@ def __str__(self):
for filename in self.files:
try:
real_dir = filename + ".stash.patch"
current_dir = SVN_STASH_DIR + "/" + self.files[filename] + ".stash.patch"
current_dir = SVN_STASH_DIR + "/" + self.files[filename] + ".stash.patch"
content += print_hr()
content += "file " + real_dir
content += print_hr()
Expand Down Expand Up @@ -210,6 +221,6 @@ def is_a_current_stash(stash_id):
stash_dir_parts = stash.root_url.split("/")
stash_dir_parts = stash_dir_parts[:len(current_dir_parts)]
stash_dir = "/".join(stash_dir_parts)
if ".svn" in os.listdir(CURRENT_DIR):
if ".svn" in os.listdir(CURRENT_DIR):
return stash_dir == CURRENT_DIR
return False