Merge remote-tracking branch 'origin/master' into develar/is
[idea/community.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / changes / shelf / ShelveChangesManager.java
index b89af90174992c0d429b3d867144de1ac91357f4..056063c90a301c970ae8b5e61c9c2ee62cc299c8 100644 (file)
@@ -754,31 +754,39 @@ public class ShelveChangesManager extends AbstractProjectComponent implements JD
   }
 
   public void saveRemainingPatches(final ShelvedChangeList changeList, final List<FilePatch> remainingPatches,
   }
 
   public void saveRemainingPatches(final ShelvedChangeList changeList, final List<FilePatch> remainingPatches,
-                            final List<ShelvedBinaryFile> remainingBinaries, CommitContext commitContext) {
-    final File newPatchDir = generateUniqueSchemePatchDir(changeList.DESCRIPTION, true);
-    final File newPath = getPatchFileInConfigDir(newPatchDir);
+                                   final List<ShelvedBinaryFile> remainingBinaries, CommitContext commitContext) {
+    ShelvedChangeList listCopy;
     try {
     try {
-      FileUtil.copy(new File(changeList.PATH), newPath);
+      listCopy = !changeList.isRecycled() ? createRecycledChangelist(changeList) : null;
     }
     catch (IOException e) {
       // do not delete if cannot recycle
       return;
     }
     }
     catch (IOException e) {
       // do not delete if cannot recycle
       return;
     }
-    final ShelvedChangeList listCopy = new ShelvedChangeList(newPath.getAbsolutePath(), changeList.DESCRIPTION,
-                                                             new ArrayList<ShelvedBinaryFile>(changeList.getBinaryFiles()));
-    listCopy.markToDelete(changeList.isMarkedToDelete());
-    listCopy.setName(newPatchDir.getName());
-
     writePatchesToFile(myProject, changeList.PATH, remainingPatches, commitContext);
 
     changeList.getBinaryFiles().retainAll(remainingBinaries);
     changeList.clearLoadedChanges();
     writePatchesToFile(myProject, changeList.PATH, remainingPatches, commitContext);
 
     changeList.getBinaryFiles().retainAll(remainingBinaries);
     changeList.clearLoadedChanges();
-    recycleChangeList(listCopy, changeList);
-    // all newly create ShelvedChangeList have to be added to SchemesManger as new scheme
-    mySchemeManager.addNewScheme(listCopy, false);
+    if (listCopy != null) {
+      recycleChangeList(listCopy, changeList);
+      // all newly create ShelvedChangeList have to be added to SchemesManger as new scheme
+      mySchemeManager.addNewScheme(listCopy, false);
+    }
     notifyStateChanged();
   }
 
     notifyStateChanged();
   }
 
+  @Nullable
+  private ShelvedChangeList createRecycledChangelist(ShelvedChangeList changeList) throws IOException {
+    final File newPatchDir = generateUniqueSchemePatchDir(changeList.DESCRIPTION, true);
+    final File newPath = getPatchFileInConfigDir(newPatchDir);
+    FileUtil.copy(new File(changeList.PATH), newPath);
+    final ShelvedChangeList listCopy = new ShelvedChangeList(newPath.getAbsolutePath(), changeList.DESCRIPTION,
+                                                             new ArrayList<ShelvedBinaryFile>(changeList.getBinaryFiles()));
+    listCopy.markToDelete(changeList.isMarkedToDelete());
+    listCopy.setName(newPatchDir.getName());
+    return listCopy;
+  }
+
   public void restoreList(@NotNull final ShelvedChangeList changeList) {
     ShelvedChangeList list = mySchemeManager.findSchemeByName(changeList.getName());
     if (list != null) {
   public void restoreList(@NotNull final ShelvedChangeList changeList) {
     ShelvedChangeList list = mySchemeManager.findSchemeByName(changeList.getName());
     if (list != null) {