How to escape @ characters in Subversion managed file names?
Asked Answered
H

11

194

For many Subversion operations, appending the '@' symbol to the end of a file or URL argument allows you to target a specific revision of that file. For example, "svn info test.txt@1234" will give information about test.txt as it existed in revision 1234.

However, when the name of the file contains an @, it is incorrectly interpreted by Subversion as a revision specifier:

svn info '[email protected]' svn: Syntax error parsing revision '.txt'

I've tried double and single quotes as well as escaping with '/', '\', and '@'. How can I tell Subversion to treat the @ symbols as part of the file name?

Herbalist answered 16/4, 2009 at 18:25 Comment(7)
Why on earth do you have filenames with @ in them? Asking for trouble, if you ask me... :-)Arvillaarvin
Very good question! :) I'm taking over a project where this character is a fundamental component of the file naming conventions and unfortunately this cannot be changed in the near future.Herbalist
Apple created this convention for all its iOS developers as of iOS 4+. All assets should be named @2x if they are for a high res display...Unpaidfor
Standard for ghetto old-style Matlab OOKatykatya
Also, if you save your private key or revocation key from Thunderbird's Enigmail, it creates a file name -- not unreasonably, given the application -- containing an at signDeuterogamy
In linux systemd services, @ character is often useMayce
@Arvillaarvin sometimes you get no choice, developers use @ signs in filenames for things like resolution-dependent variantsDeuterogamy
V
288

From the SVN book (emphasis added):

The perceptive reader is probably wondering at this point whether the peg revision syntax causes problems for working copy paths or URLs that actually have at signs in them. After all, how does svn know whether news@11 is the name of a directory in my tree or just a syntax for “revision 11 of news”? Thankfully, while svn will always assume the latter, there is a trivial workaround. You need only append an at sign to the end of the path, such as news@11@. svn cares only about the last at sign in the argument, and it is not considered illegal to omit a literal peg revision specifier after that at sign. This workaround even applies to paths that end in an at sign—you would use filename@@ to talk about a file named filename@.

Vinaigrette answered 16/4, 2009 at 18:42 Comment(3)
Note that for using "svn diff" you need to add revision parameter. "svn up @file@" works, but "svn diff @file@" doesn't work. You need to use "svn diff -r HEAD @file@"Marcela
Note for the SVN book: files can exist without extensions, even on Windows, so news@11 could be a file, as well.Comintern
Note that for some commands, like rename, an argument can be either a versioned item or a local file name. In the case of rename, the target also gets scanned for a pinned revision, but it might then afterwards be treated as a plain name. For example, if you want to rename @foo to @bar, svn rename @foo@ @bar will complain about @bar; but if you make it svn rename @foo@ @bar@, the new name will be literally @bar@. To avoid this, add ./ (or .\ on windows) to make it clear it's a local path: svn rename @foo@ ./@bar.Wot
A
83

The original answer is correct, but perhaps not explicit enough. The particular unix command line options are as follows:

svn info '[email protected]@'

or

svn info "[email protected]@"

or

svn info image\@2x.png\@

I just tested all three.

Amphitheater answered 21/2, 2011 at 22:19 Comment(4)
I also tested svn info [email protected]@ and it worked, too. Yes, no quotes or slashes!Jacobsohn
The necessity for quoting depends on your shell - I use KSH and for sure you need the quotes (as '@' is a sign you want a process run in the background). YMMV depending on shell.Amphitheater
Yep. My mileage was on the bash highway :)Jacobsohn
@Jacobsohn Now I cannot make it fail - its working fine without the quotes in ksh. I don't know why I thought I needed them - maybe some other issue - it was 2 years ago I posted this...Amphitheater
E
14

Solution for adding multiple files in different sub-folders:

for file in $(find ./ -type f -name "*@*.png"); do svn add $file@; done

Just replace the "png" in "@.png" to the kind of files you want to add.

Emulsify answered 6/9, 2012 at 3:17 Comment(2)
be sure to quote or escape your file names (and do case-insensitive matching). also there's no need to treat files with @ in their name as a special case, you can safely append the @ symbol onto all file names: for file in $(find ./ -type f -iname "*.png"); do svn add "$file@"; done. also, doesn't this approach leave your svn repo with a file/directory structure inconsistent with the working local copy?Totalitarian
using exec of find might be eaiser: find . -type f -name "*@*.png" -exec svn add {}@ \;Dave
Z
12

to add the following file : [email protected] do the following: svn add image\@2x.png@

Zannini answered 16/12, 2010 at 16:26 Comment(0)
V
12

Simply add

@

at the of the file you need to use, no matter what SVN command it is, e.g.:

[email protected]

to

[email protected]@
Vaso answered 25/7, 2017 at 20:17 Comment(0)
S
8

In my case I needed to remove files from a SVN repo that contained an @ sign:

This wouldn't work:

svn remove 'src/assets/images/hi_res/[email protected]'

But this did:

svn remove 'src/assets/images/hi_res/[email protected]@'
Shorten answered 22/9, 2011 at 23:37 Comment(0)
E
6

To add multiple files, there is alternative solution:

svn status | grep \.png | awk '{print $2"@"}'| xargs svn add
Enyo answered 23/7, 2015 at 9:45 Comment(2)
Please explain your answer.Basel
You can use awk instead of grep: svn status | awk '/\.png/ {print $2"@"}'| xargs svn addUnship
S
1

For svn commands with 2 arguments like "move", you must append "@" only at left (first) parameter. For example:

$ svn add README@txt@
A         README@txt

$ svn move README@txt@ README2@txt
A         README2@txt
D         README@txt


$ svn status
A       README2@txt

$ svn commit -m "blah"
Adding         README2@txt
Transmitting file data .
Committed revision 168.

$ svn delete README2@txt@
D         README2@txt

$ svn commit -m "blahblah"
*Deleting       README2@txt

Committed revision 169.

This line is important: $ svn move README@txt@ README2@txt

As you can see, we don't need to append "@" at "README2@txt"

Smithson answered 20/2, 2014 at 10:44 Comment(0)
D
0

@David H

I just tried a similar command without escaping the @ symbols and it still works fine

svn ci splash.png [email protected]@

This is on GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0) and svn 1.6.16

Dagney answered 26/8, 2011 at 9:22 Comment(0)
H
0

The only solution that worked for me was the same suggested by @NPike

svn revert 'path/to/filename@ext@'

Hotspur answered 5/3, 2018 at 13:52 Comment(2)
Are you sure that this should be a new response to the original question? This should rather be an upvote or commentMonodic
sorry, my bad, I can't add comment yetHotspur
L
0

I had the problem today with filenames generated from email addresses (not a very good idea!).

Solution, using printf options of find, and shell expansion

 svn add  $(find . -name "*@*.png" -printf "%p@ ")
Lingual answered 19/4, 2018 at 10:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.