added renameremote command
This commit is contained in:
		
					parent
					
						
							
								ed1a0926c1
							
						
					
				
			
			
				commit
				
					
						c0c38e986d
					
				
			
		
					 8 changed files with 80 additions and 13 deletions
				
			
		|  | @ -11,6 +11,9 @@ git-annex (7.20190323) UNRELEASED; urgency=medium | ||||||
|     syncing with are export/import remotes. |     syncing with are export/import remotes. | ||||||
|   * sync: When listing contents on an import remote fails, proceed with |   * sync: When listing contents on an import remote fails, proceed with | ||||||
|     other syncing instead of aborting. |     other syncing instead of aborting. | ||||||
|  |   * renameremote: New command, changes the name that is used to enable  | ||||||
|  |     a special remote. Especially useful when you want to reuse the name | ||||||
|  |     of an old remote for something new. | ||||||
| 
 | 
 | ||||||
|  -- Joey Hess <id@joeyh.name>  Tue, 09 Apr 2019 14:07:53 -0400 |  -- Joey Hess <id@joeyh.name>  Tue, 09 Apr 2019 14:07:53 -0400 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -54,6 +54,7 @@ import qualified Command.Init | ||||||
| import qualified Command.Describe | import qualified Command.Describe | ||||||
| import qualified Command.InitRemote | import qualified Command.InitRemote | ||||||
| import qualified Command.EnableRemote | import qualified Command.EnableRemote | ||||||
|  | import qualified Command.RenameRemote | ||||||
| import qualified Command.EnableTor | import qualified Command.EnableTor | ||||||
| import qualified Command.Multicast | import qualified Command.Multicast | ||||||
| import qualified Command.Expire | import qualified Command.Expire | ||||||
|  | @ -145,6 +146,7 @@ cmds testoptparser testrunner mkbenchmarkgenerator = | ||||||
| 	, Command.Describe.cmd | 	, Command.Describe.cmd | ||||||
| 	, Command.InitRemote.cmd | 	, Command.InitRemote.cmd | ||||||
| 	, Command.EnableRemote.cmd | 	, Command.EnableRemote.cmd | ||||||
|  | 	, Command.RenameRemote.cmd | ||||||
| 	, Command.EnableTor.cmd | 	, Command.EnableTor.cmd | ||||||
| 	, Command.Multicast.cmd | 	, Command.Multicast.cmd | ||||||
| 	, Command.Reinject.cmd | 	, Command.Reinject.cmd | ||||||
|  |  | ||||||
							
								
								
									
										41
									
								
								Command/RenameRemote.hs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								Command/RenameRemote.hs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,41 @@ | ||||||
|  | {- git-annex command | ||||||
|  |  - | ||||||
|  |  - Copyright 2019 Joey Hess <id@joeyh.name> | ||||||
|  |  - | ||||||
|  |  - Licensed under the GNU AGPL version 3 or higher. | ||||||
|  |  -} | ||||||
|  | 
 | ||||||
|  | module Command.RenameRemote where | ||||||
|  | 
 | ||||||
|  | import Command | ||||||
|  | import qualified Logs.Remote | ||||||
|  | import qualified Types.Remote as R | ||||||
|  | import qualified Remote | ||||||
|  | 
 | ||||||
|  | import qualified Data.Map as M | ||||||
|  | 
 | ||||||
|  | cmd :: Command | ||||||
|  | cmd = command "renameremote" SectionSetup | ||||||
|  | 	"changes name of special remote" | ||||||
|  | 	(paramPair paramName paramName) | ||||||
|  | 	(withParams seek) | ||||||
|  | 
 | ||||||
|  | seek :: CmdParams -> CommandSeek | ||||||
|  | seek = withWords (commandAction . start) | ||||||
|  | 
 | ||||||
|  | start :: [String] -> CommandStart | ||||||
|  | start (oldname:newname:[]) = do | ||||||
|  | 	m <- Logs.Remote.readRemoteLog | ||||||
|  | 	Remote.nameToUUID' oldname >>= \case | ||||||
|  | 		Left e -> giveup e | ||||||
|  | 		Right u -> case M.lookup u m of | ||||||
|  | 			Nothing -> giveup "That is not a special remote." | ||||||
|  | 			Just cfg -> do | ||||||
|  | 				showStart' "rename" Nothing | ||||||
|  | 				next $ perform u cfg newname | ||||||
|  | start _ = giveup "Specify an old name (or uuid or description) and a new name." | ||||||
|  | 
 | ||||||
|  | perform :: UUID -> R.RemoteConfig -> String -> CommandPerform | ||||||
|  | perform u cfg newname = do | ||||||
|  | 	Logs.Remote.configSet u (M.insert "name" newname cfg) | ||||||
|  | 	next $ return True | ||||||
|  | @ -32,6 +32,8 @@ by using eg, `git-annex reinject`.) | ||||||
| 
 | 
 | ||||||
| [[git-annex-untrust]](1) | [[git-annex-untrust]](1) | ||||||
| 
 | 
 | ||||||
|  | [[git-annex-renameremote]](1) | ||||||
|  | 
 | ||||||
| [[git-annex-expire]](1) | [[git-annex-expire]](1) | ||||||
| 
 | 
 | ||||||
| [[git-annex-fsck]](1) | [[git-annex-fsck]](1) | ||||||
|  |  | ||||||
|  | @ -27,16 +27,26 @@ All special remotes support encryption. You can specify | ||||||
| address associated with a key). For details about ways to configure | address associated with a key). For details about ways to configure | ||||||
| encryption, see <https://git-annex.branchable.com/encryption/> | encryption, see <https://git-annex.branchable.com/encryption/> | ||||||
| 
 | 
 | ||||||
| If you anticipate using the new special remote in other clones of the | Once a special remote has been initialized once with this command, | ||||||
| repository, you can pass "autoenable=true". Then when [[git-annex-init]](1) | other clones of the repository can also be set up to access it using | ||||||
|  | `git annex enableremote`. | ||||||
|  | 
 | ||||||
|  | To avoid `git annex enableremote` needing to be run, | ||||||
|  | you can pass "autoenable=true". Then when [[git-annex-init]](1) | ||||||
| is run in a new clone, it will attempt to enable the special remote. Of | is run in a new clone, it will attempt to enable the special remote. Of | ||||||
| course, this works best when the special remote does not need anything | course, this works best when the special remote does not need anything | ||||||
| special to be done to get it enabled. | special to be done to get it enabled. | ||||||
| 
 | 
 | ||||||
|  | The name you provide for the remote can't be one that's been used for any | ||||||
|  | other special remote before, because `git-annex enableremote` uses the name | ||||||
|  | to identify which special remote to enable. If some old special remote | ||||||
|  | that's no longer used has taken the name you want to reuse, you might | ||||||
|  | want to use `git annex renameremote`. | ||||||
|  | 
 | ||||||
| Normally, git-annex generates a new UUID for the new special remote. | Normally, git-annex generates a new UUID for the new special remote. | ||||||
| If you want to, you can specify a UUID for it to use, by passing a | If you want to, you can specify a UUID for it to use, by passing a | ||||||
| uuid=whatever parameter. This can be useful in some situations, eg when the | uuid=whatever parameter. This can be useful in some situations, eg when the | ||||||
| same data can be accessed via two different special remote backends. | same data can be accessed via two different remote backends. | ||||||
| But if in doubt, don't do this. | But if in doubt, don't do this. | ||||||
| 
 | 
 | ||||||
| # OPTIONS | # OPTIONS | ||||||
|  | @ -55,6 +65,8 @@ But if in doubt, don't do this. | ||||||
| 
 | 
 | ||||||
| [[git-annex-enableremote]](1) | [[git-annex-enableremote]](1) | ||||||
| 
 | 
 | ||||||
|  | [[git-annex-renameremote]](1) | ||||||
|  | 
 | ||||||
| # AUTHOR | # AUTHOR | ||||||
| 
 | 
 | ||||||
| Joey Hess <id@joeyh.name> | Joey Hess <id@joeyh.name> | ||||||
|  |  | ||||||
|  | @ -225,6 +225,12 @@ subdirectories). | ||||||
|    |    | ||||||
|   See [[git-annex-enableremote]](1) for details. |   See [[git-annex-enableremote]](1) for details. | ||||||
| 
 | 
 | ||||||
|  | * `renameremote` | ||||||
|  | 
 | ||||||
|  |   Renames a special remote. | ||||||
|  | 
 | ||||||
|  |   See [[git-annex-renameremote]](1) for details. | ||||||
|  | 
 | ||||||
| * `enable-tor` | * `enable-tor` | ||||||
| 
 | 
 | ||||||
|   Sets up tor hidden service. |   Sets up tor hidden service. | ||||||
|  |  | ||||||
|  | @ -9,16 +9,15 @@ with the same name, and so enableremote would need to be run with a uuid | ||||||
| instead of a name to specify which one to enable, which is not a desirable | instead of a name to specify which one to enable, which is not a desirable | ||||||
| state of affairs. | state of affairs. | ||||||
| 
 | 
 | ||||||
| So, add `git annex renameremote oldname newname`. This could also do a `git | So, add `git annex renameremote oldname newname`. Updates the remote.log | ||||||
|  | with the new name. | ||||||
|  | 
 | ||||||
|  | This could also do a `git | ||||||
| remote rename`, or equivilant. (`git remote rename` gets confused by special | remote rename`, or equivilant. (`git remote rename` gets confused by special | ||||||
| remotes not having a fetch url and fails; this can be worked around by | remotes not having a fetch url and fails; this can be worked around by | ||||||
| manually renaming the stanza in git config.) | manually renaming the stanza in git config.) But.. Perhaps it's better to | ||||||
|  | keep it simple and not do that. There's no necessarily a correspondance | ||||||
|  | between the name of a remote in the local repo and the name of a | ||||||
|  | special remote in the remote.log. | ||||||
| 
 | 
 | ||||||
| Implementing that would need a way to remove the old name from remote.log. | [[done]] --[[Joey]] | ||||||
| We can't remove lines from union merged files, but what we could do is |  | ||||||
| add a new line like: |  | ||||||
| 
 |  | ||||||
| 	- name=oldname timestamp=<latest> |  | ||||||
| 
 |  | ||||||
| And in parsing remote.log, if the UUID is "-", don't include the |  | ||||||
| remote with that name in the the resulting map. |  | ||||||
|  |  | ||||||
|  | @ -104,6 +104,7 @@ Extra-Source-Files: | ||||||
|   doc/git-annex-reinject.mdwn |   doc/git-annex-reinject.mdwn | ||||||
|   doc/git-annex-rekey.mdwn |   doc/git-annex-rekey.mdwn | ||||||
|   doc/git-annex-remotedaemon.mdwn |   doc/git-annex-remotedaemon.mdwn | ||||||
|  |   doc/git-annex-renameremote.mdwn | ||||||
|   doc/git-annex-repair.mdwn |   doc/git-annex-repair.mdwn | ||||||
|   doc/git-annex-required.mdwn |   doc/git-annex-required.mdwn | ||||||
|   doc/git-annex-resolvemerge.mdwn |   doc/git-annex-resolvemerge.mdwn | ||||||
|  | @ -766,6 +767,7 @@ Executable git-annex | ||||||
|     Command.Reinit |     Command.Reinit | ||||||
|     Command.Reinject |     Command.Reinject | ||||||
|     Command.RemoteDaemon |     Command.RemoteDaemon | ||||||
|  |     Command.RenameRemote | ||||||
|     Command.Repair |     Command.Repair | ||||||
|     Command.Required |     Command.Required | ||||||
|     Command.ResolveMerge |     Command.ResolveMerge | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Joey Hess
				Joey Hess