Push secret changesets

…衆ロ難τιáo~ 提交于 2019-12-03 12:19:11

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!

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).

schlamar

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.

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.

  1. Mark all the secret changesets you want to transfer as draft
  2. In the source repo run hg bundle -r last_draft_rev bundlefile.hg path\to\backup\repo
  3. In the destination repo run hg unbundle bundlefile.hg
  4. The changesets will come into the backup as DRAFT
  5. 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.

@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
mischab1

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!