From 911ac9a3bad256e47baee708b2a7afa1b2e75872 Mon Sep 17 00:00:00 2001 From: Sepehr Lajevardi Date: Thu, 29 Aug 2013 05:02:32 +0430 Subject: [PATCH 1/5] Check for file existence when clearing stash. --- svn_stash_register.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/svn_stash_register.py b/svn_stash_register.py index 99df7fb..7c6f5b3 100755 --- a/svn_stash_register.py +++ b/svn_stash_register.py @@ -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) @@ -137,12 +137,17 @@ 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() + + filepath = SVN_STASH_DIR + "/" + str(self.key) + if os.path.isfile(filepath): + result += os.popen("rm " + filepath).read() def load(self,stash_id): try: @@ -173,7 +178,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() @@ -210,6 +215,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 From 9e3d16881bec2724f2a30c0b8828dd74a595e5f4 Mon Sep 17 00:00:00 2001 From: Sepehr Lajevardi Date: Thu, 29 Aug 2013 05:03:54 +0430 Subject: [PATCH 2/5] Check for file existence when poping stash. --- svn_stash_register.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/svn_stash_register.py b/svn_stash_register.py index 7c6f5b3..4621be7 100755 --- a/svn_stash_register.py +++ b/svn_stash_register.py @@ -112,12 +112,18 @@ 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 + randkey = self.files[target_file] + filepath = SVN_STASH_DIR + "/" + str(randkey) + ".stash.patch" + + if os.path.isfile(filepath): + result = os.popen("patch -p0 < " + filepath).read() + result += os.popen("rm " + filepath).read() + #print "pop " + target_file + #delete the file of svn_stash - result += os.popen("rm " + SVN_STASH_DIR + "/" + str(self.key)).read() + filepath = SVN_STASH_DIR + "/" + str(self.key) + if os.path.isfile(filepath): + result += os.popen("rm " + filepath).read() def write(self): #Create file for svn stash From fa46d84430785f9346653938e894c3fd220a6939 Mon Sep 17 00:00:00 2001 From: Sepehr Lajevardi Date: Thu, 29 Aug 2013 05:13:36 +0430 Subject: [PATCH 3/5] Print error when a stash file cannot be found. --- svn-stash.py | 10 +++++----- svn_stash_register.py | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/svn-stash.py b/svn-stash.py index ba6c8f7..69ac844 100755 --- a/svn-stash.py +++ b/svn-stash.py @@ -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() @@ -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" @@ -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: @@ -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) diff --git a/svn_stash_register.py b/svn_stash_register.py index 4621be7..9db7ca0 100755 --- a/svn_stash_register.py +++ b/svn_stash_register.py @@ -119,11 +119,15 @@ def pop(self): result = os.popen("patch -p0 < " + filepath).read() result += os.popen("rm " + filepath).read() #print "pop " + target_file + else: + print 'randFile cannot be found, patch failed.' #delete the file of svn_stash 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 write(self): #Create file for svn stash @@ -150,10 +154,14 @@ def clear(self): 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: From e09a70a8af6aac34baecbdbd9dab10334c6fe3d2 Mon Sep 17 00:00:00 2001 From: Sepehr Lajevardi Date: Thu, 29 Aug 2013 05:36:12 +0430 Subject: [PATCH 4/5] Pop should not remove files by itself, as it is followed by a delete_stash() call. --- svn_stash_register.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/svn_stash_register.py b/svn_stash_register.py index 9db7ca0..93d460a 100755 --- a/svn_stash_register.py +++ b/svn_stash_register.py @@ -117,17 +117,9 @@ def pop(self): if os.path.isfile(filepath): result = os.popen("patch -p0 < " + filepath).read() - result += os.popen("rm " + filepath).read() #print "pop " + target_file else: - print 'randFile cannot be found, patch failed.' - - #delete the file of svn_stash - filepath = SVN_STASH_DIR + "/" + str(self.key) - if os.path.isfile(filepath): - result += os.popen("rm " + filepath).read() - else: - print 'registerFile cannot be found.' + print 'Patch file cannot be found.' def write(self): #Create file for svn stash From ab0ccdb79521a93a8b49b44845039bc71efa2c5a Mon Sep 17 00:00:00 2001 From: Sepehr Lajevardi Date: Thu, 29 Aug 2013 05:46:35 +0430 Subject: [PATCH 5/5] Use svn patch instead of patch -p0. --- svn_stash_register.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svn_stash_register.py b/svn_stash_register.py index 93d460a..e67fc29 100755 --- a/svn_stash_register.py +++ b/svn_stash_register.py @@ -116,7 +116,7 @@ def pop(self): filepath = SVN_STASH_DIR + "/" + str(randkey) + ".stash.patch" if os.path.isfile(filepath): - result = os.popen("patch -p0 < " + filepath).read() + result = os.popen("svn patch " + filepath).read() #print "pop " + target_file else: print 'Patch file cannot be found.'