Show More
@@ -29,7 +29,7 b'' | |||||
29 |
|
29 | |||
30 | from mercurial import util, commands, cmdutil |
|
30 | from mercurial import util, commands, cmdutil | |
31 | from mercurial.i18n import _ |
|
31 | from mercurial.i18n import _ | |
32 | import os |
|
32 | import os, stat | |
33 |
|
33 | |||
34 | def purge(ui, repo, *dirs, **opts): |
|
34 | def purge(ui, repo, *dirs, **opts): | |
35 | '''removes files not tracked by Mercurial |
|
35 | '''removes files not tracked by Mercurial | |
@@ -72,6 +72,13 b' def purge(ui, repo, *dirs, **opts):' | |||||
72 | else: |
|
72 | else: | |
73 | ui.write('%s%s' % (name, eol)) |
|
73 | ui.write('%s%s' % (name, eol)) | |
74 |
|
74 | |||
|
75 | def removefile(path): | |||
|
76 | # read-only files cannot be unlinked under Windows | |||
|
77 | s = os.stat(path) | |||
|
78 | if (s.st_dev & stat.S_IWRITE) == 0: | |||
|
79 | os.chmod(path, s.st_mode | stat.S_IWRITE) | |||
|
80 | os.remove(path) | |||
|
81 | ||||
75 | directories = [] |
|
82 | directories = [] | |
76 | match = cmdutil.match(repo, dirs, opts) |
|
83 | match = cmdutil.match(repo, dirs, opts) | |
77 | match.dir = directories.append |
|
84 | match.dir = directories.append | |
@@ -79,7 +86,7 b' def purge(ui, repo, *dirs, **opts):' | |||||
79 |
|
86 | |||
80 | for f in util.sort(status[4] + status[5]): |
|
87 | for f in util.sort(status[4] + status[5]): | |
81 | ui.note(_('Removing file %s\n') % f) |
|
88 | ui.note(_('Removing file %s\n') % f) | |
82 |
remove( |
|
89 | remove(removefile, f) | |
83 |
|
90 | |||
84 | for f in util.sort(directories)[::-1]: |
|
91 | for f in util.sort(directories)[::-1]: | |
85 | if match(f) and not os.listdir(repo.wjoin(f)): |
|
92 | if match(f) and not os.listdir(repo.wjoin(f)): |
@@ -34,6 +34,12 b' ls' | |||||
34 |
|
34 | |||
35 | echo % delete an untracked file |
|
35 | echo % delete an untracked file | |
36 | touch untracked_file |
|
36 | touch untracked_file | |
|
37 | touch untracked_file_readonly | |||
|
38 | python <<EOF | |||
|
39 | import os, stat | |||
|
40 | f= 'untracked_file_readonly' | |||
|
41 | os.chmod(f, os.stat(f).st_mode & ~stat.S_IWRITE) | |||
|
42 | EOF | |||
37 | hg purge -p |
|
43 | hg purge -p | |
38 | hg purge -v |
|
44 | hg purge -v | |
39 | ls |
|
45 | ls |
@@ -15,7 +15,9 b' directory' | |||||
15 | r1 |
|
15 | r1 | |
16 | % delete an untracked file |
|
16 | % delete an untracked file | |
17 | untracked_file |
|
17 | untracked_file | |
|
18 | untracked_file_readonly | |||
18 | Removing file untracked_file |
|
19 | Removing file untracked_file | |
|
20 | Removing file untracked_file_readonly | |||
19 | directory |
|
21 | directory | |
20 | r1 |
|
22 | r1 | |
21 | % delete an untracked file in a tracked directory |
|
23 | % delete an untracked file in a tracked directory |
General Comments 0
You need to be logged in to leave comments.
Login now