问题
That may look paradoxical, I know that secret changesets are meant to be private, but what if I want to backup those secret changesets?
I work with some branches in parallel and sometimes I want to push one, but not the others. To achieve that, I work in separate clones but I hate that.
So now mercurial has phases, I can make secret branches and have everything in the same repository. The problem is that between the beginning of the secret branch and its publication, I want to backup those secret changesets (I have a clone in another machine just to hold my backups in case something happens with my local repo or my machine).
Is there a way of doing that or my workflow is completly wrong?
回答1:
It seems like phases are still relatively new and some workflows, such as this, don't seem to be included, yet. As of 2013-03-19, I believe the only way you can do this is manually changing the phases from secret to public.
You can use these commands from the command line:
for /f "delims=" %a in ('hg log --template "{rev} " -r "secret()"') do @set secret=%a
hg phase -d %secret%
hg push -f
hg phase -sf %secret%
This doesn't change the commits to secret on the repository you are pushing to, I tried to change the push to do this (but was unsuccessful):
hg push -f --remotecmd hg phase -sf %secret%
The commits would have to match exactly for the remote hg command
to work, but I couldn't get it to change on the remote repository anyway.
============================================================
If you want to use a GUI like TortoiseHG Workbench you will have to do this all manually (change the phases in the GUI on any repositories you want to) at the moment. Sorry, and hopefully, we can find a better solution, soon!
回答2:
No need to mark anything secret. If you only want to push one branch, use:
hg push -r REV
This will push REV and its ancestors only.
Secret is good for Mercurial patch queue revisions, since they can't be pushed anyway and it prevents a local clone from copying them.
Draft is good for tracking unpushed changes. If you still want to back them up, pushing them will flip them to Public, but you can reset them back to draft (as compared to another repository) with:
hg phase -fd 'outgoing(URL)'
(URL can be blank for the default push repo).
回答3:
The best approach is a combination of @mischab1's answer, @mark-tolonen's answer and aliases.
By following mischab1's answer, you make sure that pushing to your backup location will not change the phase to "public".
Second step would be to add the backup location to your repository's hgrc/paths:
[paths]
default = ...
backup = backup_location
The next step is to define a backup command via alias in the global hgrc, e.g. "bubr" (for backup current branch) or "burev" (backup current rev).
[alias]
bubr = push -b . backup
burev = push -r . backup
hg bubr
or hg burev
will then push the current branch/revision to the location defined as "backup" path.
Edit This still has the drawback that you could accidentally push all changes with "hg push" so defining also an hg pubr
command to push the current branch and not using "hg push" per default might be helpful.
回答4:
This is the best I have come up with so far. I think its essentially equivalent to what you want push/pull to be able to do.
- Mark all the secret changesets you want to transfer as draft
- In the source repo run
hg bundle -r last_draft_rev bundlefile.hg path\to\backup\repo
- In the destination repo run
hg unbundle bundlefile.hg
- The changesets will come into the backup as DRAFT
- Mark the first draft changeset as secret, and all its descendants will be marked thusly
I couldn't get #2 to work if the changesets were still marked secret.
回答5:
@echo off
rem hgfullpull_naive.cmd
setlocal
set SRC_REPO=%~f1
set DST_REPO=%~f2
set TMP_DIR=%TEMP%\%~n0.tmp
set NODES_LIST=%TMP_DIR%\%~n0.%RANDOM%.tmp
if "%SRC_REPO%"=="" exit /b 1
if "%DST_REPO%"=="" exit /b 1
if "%SRC_REPO%"=="%DST_REPO%" exit /b 1
call :ALL
del /Q "%NODES_LIST%"
endlocal
goto :eof
:ALL
md "%TMP_DIR%"
hg log --rev "secret()" --template "{node}\n" --repository "%SRC_REPO%" >"%NODES_LIST%" || exit /b 1
call :CHANGE_PHASE "%SRC_REPO%" --draft
hg pull --repository "%DST_REPO%" "%SRC_REPO%"
call :CHANGE_PHASE "%SRC_REPO%" --secret
call :CHANGE_PHASE "%DST_REPO%" --secret
goto :eof
:CHANGE_PHASE
setlocal
set REPO=%~1
set PHASE=%~2
for /F "eol=; delims= usebackq" %%i IN ("%NODES_LIST%") DO (hg phase %PHASE% --force --rev %%i --repository "%REPO%")
endlocal
goto :eof
回答6:
The easiest thing to do now-days, is to mark your backup repository as non-publishing by adding the following to its hgrc config file.
[phases]
publish = False
See Mercurial's Wiki for more info.
来源:https://stackoverflow.com/questions/10029718/push-secret-changesets