Show More
@@ -789,6 +789,24 b' def bookmark(ui, repo, mark=None, rev=No' | |||||
789 | marks = repo._bookmarks |
|
789 | marks = repo._bookmarks | |
790 | cur = repo.changectx('.').node() |
|
790 | cur = repo.changectx('.').node() | |
791 |
|
791 | |||
|
792 | def checkformat(mark): | |||
|
793 | if "\n" in mark: | |||
|
794 | raise util.Abort(_("bookmark name cannot contain newlines")) | |||
|
795 | mark = mark.strip() | |||
|
796 | if not mark: | |||
|
797 | raise util.Abort(_("bookmark names cannot consist entirely of " | |||
|
798 | "whitespace")) | |||
|
799 | return mark | |||
|
800 | ||||
|
801 | def checkconflict(repo, mark, force=False): | |||
|
802 | if mark in marks and not force: | |||
|
803 | raise util.Abort(_("bookmark '%s' already exists " | |||
|
804 | "(use -f to force)") % mark) | |||
|
805 | if ((mark in repo.branchmap() or mark == repo.dirstate.branch()) | |||
|
806 | and not force): | |||
|
807 | raise util.Abort( | |||
|
808 | _("a bookmark cannot have the name of an existing branch")) | |||
|
809 | ||||
792 | if delete: |
|
810 | if delete: | |
793 | if mark is None: |
|
811 | if mark is None: | |
794 | raise util.Abort(_("bookmark name required")) |
|
812 | raise util.Abort(_("bookmark name required")) | |
@@ -801,13 +819,12 b' def bookmark(ui, repo, mark=None, rev=No' | |||||
801 | return |
|
819 | return | |
802 |
|
820 | |||
803 | if rename: |
|
821 | if rename: | |
|
822 | if mark is None: | |||
|
823 | raise util.Abort(_("new bookmark name required")) | |||
|
824 | mark = checkformat(mark) | |||
804 | if rename not in marks: |
|
825 | if rename not in marks: | |
805 | raise util.Abort(_("bookmark '%s' does not exist") % rename) |
|
826 | raise util.Abort(_("bookmark '%s' does not exist") % rename) | |
806 | if mark in marks and not force: |
|
827 | checkconflict(repo, mark, force) | |
807 | raise util.Abort(_("bookmark '%s' already exists " |
|
|||
808 | "(use -f to force)") % mark) |
|
|||
809 | if mark is None: |
|
|||
810 | raise util.Abort(_("new bookmark name required")) |
|
|||
811 | marks[mark] = marks[rename] |
|
828 | marks[mark] = marks[rename] | |
812 | if repo._bookmarkcurrent == rename and not inactive: |
|
829 | if repo._bookmarkcurrent == rename and not inactive: | |
813 | bookmarks.setcurrent(repo, mark) |
|
830 | bookmarks.setcurrent(repo, mark) | |
@@ -816,22 +833,11 b' def bookmark(ui, repo, mark=None, rev=No' | |||||
816 | return |
|
833 | return | |
817 |
|
834 | |||
818 | if mark is not None: |
|
835 | if mark is not None: | |
819 | if "\n" in mark: |
|
836 | mark = checkformat(mark) | |
820 | raise util.Abort(_("bookmark name cannot contain newlines")) |
|
|||
821 | mark = mark.strip() |
|
|||
822 | if not mark: |
|
|||
823 | raise util.Abort(_("bookmark names cannot consist entirely of " |
|
|||
824 | "whitespace")) |
|
|||
825 | if inactive and mark == repo._bookmarkcurrent: |
|
837 | if inactive and mark == repo._bookmarkcurrent: | |
826 | bookmarks.setcurrent(repo, None) |
|
838 | bookmarks.setcurrent(repo, None) | |
827 | return |
|
839 | return | |
828 | if mark in marks and not force: |
|
840 | checkconflict(repo, mark, force) | |
829 | raise util.Abort(_("bookmark '%s' already exists " |
|
|||
830 | "(use -f to force)") % mark) |
|
|||
831 | if ((mark in repo.branchmap() or mark == repo.dirstate.branch()) |
|
|||
832 | and not force): |
|
|||
833 | raise util.Abort( |
|
|||
834 | _("a bookmark cannot have the name of an existing branch")) |
|
|||
835 | if rev: |
|
841 | if rev: | |
836 | marks[mark] = scmutil.revsingle(repo, rev).node() |
|
842 | marks[mark] = scmutil.revsingle(repo, rev).node() | |
837 | else: |
|
843 | else: |
@@ -217,12 +217,31 b' reject bookmark name with newline' | |||||
217 | abort: bookmark name cannot contain newlines |
|
217 | abort: bookmark name cannot contain newlines | |
218 | [255] |
|
218 | [255] | |
219 |
|
219 | |||
|
220 | $ hg bookmark -m Z ' | |||
|
221 | > ' | |||
|
222 | abort: bookmark name cannot contain newlines | |||
|
223 | [255] | |||
|
224 | ||||
220 | bookmark with existing name |
|
225 | bookmark with existing name | |
221 |
|
226 | |||
222 | $ hg bookmark Z |
|
227 | $ hg bookmark Z | |
223 | abort: bookmark 'Z' already exists (use -f to force) |
|
228 | abort: bookmark 'Z' already exists (use -f to force) | |
224 | [255] |
|
229 | [255] | |
225 |
|
230 | |||
|
231 | $ hg bookmark -m Y Z | |||
|
232 | abort: bookmark 'Z' already exists (use -f to force) | |||
|
233 | [255] | |||
|
234 | ||||
|
235 | bookmark with name of branch | |||
|
236 | ||||
|
237 | $ hg bookmark default | |||
|
238 | abort: a bookmark cannot have the name of an existing branch | |||
|
239 | [255] | |||
|
240 | ||||
|
241 | $ hg bookmark -m Y default | |||
|
242 | abort: a bookmark cannot have the name of an existing branch | |||
|
243 | [255] | |||
|
244 | ||||
226 | force bookmark with existing name |
|
245 | force bookmark with existing name | |
227 |
|
246 | |||
228 | $ hg bookmark -f Z |
|
247 | $ hg bookmark -f Z | |
@@ -247,6 +266,10 b' bookmark name with whitespace only' | |||||
247 | abort: bookmark names cannot consist entirely of whitespace |
|
266 | abort: bookmark names cannot consist entirely of whitespace | |
248 | [255] |
|
267 | [255] | |
249 |
|
268 | |||
|
269 | $ hg bookmark -m Y ' ' | |||
|
270 | abort: bookmark names cannot consist entirely of whitespace | |||
|
271 | [255] | |||
|
272 | ||||
250 | invalid bookmark |
|
273 | invalid bookmark | |
251 |
|
274 | |||
252 | $ hg bookmark 'foo:bar' |
|
275 | $ hg bookmark 'foo:bar' |
General Comments 0
You need to be logged in to leave comments.
Login now