Commits

Anonymous committed 98c2d86

another stab at making the untracked files collision problem work
now we store the offending untracked file away so that the stashed patch can apply cleanly, we restore it if update files

  • Participants
  • Parent commits cbcbf75

Comments (0)

Files changed (1)

File hgext/tasks.py

                     if filesha(repo, f) != shas[f]:
                         raise util.Abort(_("untracked file in working directory differs from file in requested revision: '%s'" % f))
 
+
+    # store all untracked files that are also in stash
+    storeuntracked(repo, untrackedinstash)
+
+    # if on task we stash and force --clean so update will not complain
     if ontask:
         opts['clean'] = True
         if stash(ui, repo, currenttask):
             cleanup(repo)
-            try:
-                res = orig(ui, repo, *args, **opts)
-            except:
-                unstash(ui, repo, currenttask)
-                raise
-        else:
-            res = orig(ui, repo, *args, **opts)
-    else:
+    # perform actual update
+    try:
         res = orig(ui, repo, *args, **opts)
+    except:
+        # revert all damage we may have done to current state
+        if ontask:
+            unstash(ui, repo, currenttask)
+            restoreuntracked(repo, untrackedinstash)
+        # now we can bail
+        raise
+
+    removeuntracked(repo)
 
     # update now complete, unstash and change current
     setcurrent(ui, repo, totask, totask)
     if totask:
-        for f in untrackedinstash:
-            ui.write("DELETING: %s\n" % util.pathto(repo.root, None, f))
-            os.unlink(util.pathto(repo.root, None, f))
         unstash(ui, repo, totask)
 
     return res
 
 
+def storeuntracked(repo, untracked):
+    if not untracked:
+        return
+    os.mkdir(repo.join('tasks/untrackedbackup'))
+    for f in untracked:
+        shaname = util.sha1(f).hexdigest()
+        util.copyfile(util.pathto(repo.root, None, f), repo.join('tasks/untrackedbackup/%s' % shaname))
+
+
+def restoreuntracked(repo, untracked):
+    for f in untracked:
+        shaname = util.sha1(f).hexdigest()
+        util.copyfile(repo.join('tasks/untrackedbackup/%s' % shaname), util.pathto(repo.root, None, f))
+
+
+def removeuntracked(repo):
+    if os.path.exists(repo.join('tasks/untrackedbackup')):
+        for f in os.listdir(repo.join('tasks/untrackedbackup')):
+            os.unlink("%s/%s" % (repo.join('tasks'), f))
+        os.rmdir(repo.join('tasks/untrackedbackup'))
+
+
 def debugtask(ui, repo, task=None, showstash=False, purge=False, force=False):
     '''tasks debug'''