User Tools

Site Tools


windows:hgsync

This is an old revision of the document!


Mercurial Sync Script

hgsync_login.cmd

hgsync_login.cmd
@echo off
 
set LOCAL_REPO="%USERPROFILE%\Documents"
set REMOTE_REPO="h:\Documents"
set SSH_REPO="ssh://%USERNAME%@sfs/Documents"
set PATH=C:\Progra~1\Mercurial;C:\Windows\System32\OpenSSH;
 
If exist "%LOCAL_REPO%\.hg" (
    If exist "%REMOTE_REPO%\.hg" (
		goto Remoteandlocal
	) else (
		goto onlylocal
	)
) else If exist "%REMOTE_REPO%\.hg" (
    goto onlyremote
) else If exist "%LOCAL_REPO%\.hg" (
	goto onlylocal
) else (
	goto missingonboth
)
 
goto end

 
:Remoteandlocal
Echo File exist remote and local
c:
cd %LOCAL_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "update from %COMPUTERNAME%"
hg pull  %REMOTE_REPO%
hg merge -t "W:\scripts\merge.bat"
hg resolve -t internal:other --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg push  %REMOTE_REPO%
h:
cd %REMOTE_REPO%
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg merge -t "W:\scripts\merge_other.bat"
hg resolve -t internal:local --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
c:
cd %LOCAL_REPO%
hg pull  %REMOTE_REPO%
hg update
goto END

:onlylocal
Echo File exist only local
mkdir %REMOTE_REPO%
H:
cd %REMOTE_REPO%
hg init
c:
cd %LOCAL_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "update from %COMPUTERNAME%"
hg push  %REMOTE_REPO%
H:
cd %REMOTE_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "remote update from %COMPUTERNAME%"
hg merge -t "W:\scripts\merge.bat"
hg resolve -t internal:other --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "remote merge update from %COMPUTERNAME%"
c:
cd %LOCAL_REPO%
hg pull  %REMOTE_REPO%
hg merge -t "W:\scripts\merge_other.bat"
hg resolve -t internal:local --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg push %REMOTE_REPO%
h:
cd %REMOTE_REPO%
hg update
goto END

:onlyremote
Echo File exist only remote
c:
cd %LOCAL_REPO%
hg init
hg pull  %REMOTE_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "update from %COMPUTERNAME%"
hg merge -t "W:\scripts\merge.bat"
hg resolve -t internal:other --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg push %REMOTE_REPO%
h:
cd %REMOTE_REPO%
hg update
goto END

:missingonboth
Echo missing on both
mkdir %LOCAL_REPO%
C:
cd %LOCAL_REPO%
hg init
mkdir %REMOTE_REPO%
H:
cd %REMOTE_REPO%
hg init
c:
cd %LOCAL_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "update from %COMPUTERNAME%"
hg push %REMOTE_REPO%
H:
cd %REMOTE_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "remote update from %COMPUTERNAME%"
hg merge -t "W:\scripts\merge.bat"
hg resolve -t internal:other --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "remote merge update from %COMPUTERNAME%"
c:
cd %LOCAL_REPO%
hg pull  %REMOTE_REPO%
hg merge -t "W:\scripts\merge_other.bat"
hg resolve -t internal:local --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg push %REMOTE_REPO%
h:
cd %REMOTE_REPO%
hg update
goto END

:END
echo done

hgsync_login_ssh.cmd

hgsync_login_ssh.cmd
@echo off
 
set LOCAL_REPO="%USERPROFILE%\Documents"
set REMOTE_REPO="h:\Documents"
set SSH_REPO="ssh://%USERNAME%@sfs/Documents"
set SSHHOST="sfs"
set PATH=C:\Progra~1\Mercurial;C:\Windows\System32\OpenSSH;C:\Windows\System32;
 
 
 
If exist "%USERPROFILE%\.ssh\id_rsa" (
    If exist "%USERPROFILE%\.ssh\known_hosts" (
		echo SSH env ready
		xcopy /Y /S H:\.ssh %USERPROFILE%\.ssh\
	) else (
		echo Setting up SSH env
		mkdir %USERPROFILE%\.ssh
		xcopy /Y /S H:\.ssh %USERPROFILE%\.ssh\
		ssh -oStrictHostKeyChecking=no %USERNAME%@%SSHHOST% "id"
	) 
) else (
		echo Setting up SSH env
		mkdir %USERPROFILE%\.ssh
		xcopy /Y /S H:\.ssh %USERPROFILE%\.ssh\
		ssh -oStrictHostKeyChecking=no %USERNAME%@%SSHHOST% "id"
)
 
If exist "%LOCAL_REPO%\.hg" (
    If exist "%REMOTE_REPO%\.hg" (
		goto Remoteandlocal
	) else (
		goto onlylocal
	)
) else If exist "%REMOTE_REPO%\.hg" (
    goto onlyremote
) else If exist "%LOCAL_REPO%\.hg" (
	goto onlylocal
) else (
	goto missingonboth
)
 
goto end

 
:Remoteandlocal
Echo File exist remote and local
c:
cd %LOCAL_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "update from %COMPUTERNAME%"
hg pull %SSH_REPO%
hg merge -t "W:\scripts\merge.bat"
hg resolve -t internal:other --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg push %SSH_REPO%
echo "remote update start"
ssh %USERNAME%@sfs "/scripts/hgsync_login.sh"
echo "remote update end"
hg pull %SSH_REPO%
hg update
goto END

:onlylocal
Echo File exist only local
echo "remote init start"
ssh %USERNAME%@sfs "/scripts/hgsync_init.sh"
echo "remote init end"
c: 
cd %LOCAL_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "update from %COMPUTERNAME%"
hg push %SSH_REPO%
echo "remote update start"
ssh %USERNAME%@sfs "/scripts/hgsync_login.sh"
echo "remote update end"
hg pull %SSH_REPO%
hg merge -t "W:\scripts\merge_other.bat"
hg resolve -t internal:local --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg push %SSH_REPO%
h:
cd %SSH_REPO%
hg update
goto END

:onlyremote
Echo File exist only remote
c:
cd %LOCAL_REPO%
hg init
hg pull %SSH_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "update from %COMPUTERNAME%"
hg merge -t "W:\scripts\merge.bat"
hg resolve -t internal:other --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg push %SSH_REPO%
echo "remote update start"
ssh %USERNAME%@sfs "/scripts/hgsync_update.sh"
echo "remote update end"
goto END

:missingonboth
Echo missing on both
mkdir %LOCAL_REPO%
C:
cd %LOCAL_REPO%
hg init
echo "remote init start"
ssh %USERNAME%@sfs "/scripts/hgsync_init.sh"
echo "remote init end"
hg addremove
hg --config ui.username=%USERNAME% commit -m "update from %COMPUTERNAME%"
hg push %SSH_REPO%
echo "remote update start"
ssh %USERNAME%@sfs "/scripts/hgsync_logout.sh"
echo "remote update end"
hg pull %SSH_REPO%
hg merge -t "W:\scripts\merge_other.bat"
hg resolve -t internal:local --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg push %SSH_REPO%
echo "remote update start"
ssh %USERNAME%@sfs "/scripts/hgsync_update.sh"
echo "remote update end"
goto END

:END
echo done

hgsync_logout.cmd

hgsync_logout.cmd
@echo off
set LOCAL_REPO="%USERPROFILE%\Documents"
set REMOTE_REPO="h:\Documents"
set PATH=C:\Progra~1\Mercurial;C:\Windows\System32\OpenSSH;
 
If exist "%LOCAL_REPO%\.hg" (
    If exist "%REMOTE_REPO%\.hg" (
		goto Remoteandlocal
	) else (
		goto onlylocal
	)
) else If exist "%REMOTE_REPO%\.hg" (
    goto onlyremote
) else If exist "%LOCAL_REPO%\.hg" (
	goto onlylocal
) else (
	goto missingonboth
)

 
 
 
:Remoteandlocal
Echo File exist remote and local
c:
cd %LOCAL_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "update from %COMPUTERNAME%"
hg pull  %REMOTE_REPO%
hg merge -t "W:\scripts\merge_other.bat"
hg resolve -t internal:local --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg push  %REMOTE_REPO%
h:
cd %REMOTE_REPO%
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg merge -t "W:\scripts\merge.bat"
hg resolve -t internal:other --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
c:
cd %LOCAL_REPO%
hg pull  %REMOTE_REPO%
hg update
goto END

:onlylocal
Echo File exist only local
mkdir %REMOTE_REPO%
H:
cd %REMOTE_REPO%
hg init
c:
cd %LOCAL_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "update from %COMPUTERNAME%"
hg push  %REMOTE_REPO%
H:
cd %REMOTE_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "remote update from %COMPUTERNAME%"
hg merge -t "W:\scripts\merge.bat"
hg resolve -t internal:other --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "remote merge update from %COMPUTERNAME%"
c:
cd %LOCAL_REPO%
hg pull  %REMOTE_REPO%
hg merge -t "W:\scripts\merge_other.bat"
hg resolve -t internal:local --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg push %REMOTE_REPO%
h:
cd %REMOTE_REPO%
hg update
goto END

:onlyremote
Echo File exist only remote
c:
cd %LOCAL_REPO%
hg init
hg pull  %REMOTE_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "update from %COMPUTERNAME%"
hg merge -t "W:\scripts\merge_other.bat"
hg resolve -t internal:local --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg push %REMOTE_REPO%
h:
cd %REMOTE_REPO%
hg update
goto END

:missingonboth
Echo missing on both
mkdir %LOCAL_REPO%
C:
cd %LOCAL_REPO%
hg init
mkdir %REMOTE_REPO%
H:
cd %REMOTE_REPO%
hg init
c:
cd %LOCAL_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "update from %COMPUTERNAME%"
hg push %REMOTE_REPO%
H:
cd %REMOTE_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "remote update from %COMPUTERNAME%"
hg merge -t "W:\scripts\merge.bat"
hg resolve -t internal:other --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "remote merge update from %COMPUTERNAME%"
c:
cd %LOCAL_REPO%
hg pull  %REMOTE_REPO%
hg merge -t "W:\scripts\merge_other.bat"
hg resolve -t internal:local --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg push %REMOTE_REPO%
h:
cd %REMOTE_REPO%
hg update
goto END

:END
echo done

hgsync_logout_ssh.cmd

hgsync_logout_ssh.cmd
@echo off
 
set LOCAL_REPO="%USERPROFILE%\Documents"
set REMOTE_REPO="h:\Documents"
set SSH_REPO="ssh://%USERNAME%@sfs/Documents"
set SSHHOST="sfs"
set PATH=C:\Progra~1\Mercurial;C:\Windows\System32\OpenSSH;C:\Windows\System32;
 
If exist "%USERPROFILE%\.ssh\id_rsa" (
    If exist "%USERPROFILE%\.ssh\known_hosts" (
		echo SSH env ready
		xcopy /Y /S H:\.ssh %USERPROFILE%\.ssh\
	) else (
		echo Setting up SSH env
		mkdir %USERPROFILE%\.ssh
		xcopy /Y /S H:\.ssh %USERPROFILE%\.ssh\
		ssh -oStrictHostKeyChecking=no %USERNAME%@%SSHHOST% "id"
	) 
) else (
		echo Setting up SSH env
		mkdir %USERPROFILE%\.ssh
		xcopy /Y /S H:\.ssh %USERPROFILE%\.ssh\
		ssh -oStrictHostKeyChecking=no %USERNAME%@%SSHHOST% "id"
)
 
If exist "%LOCAL_REPO%\.hg" (
    If exist "%REMOTE_REPO%\.hg" (
		goto Remoteandlocal
	) else (
		goto onlylocal
	)
) else If exist "%REMOTE_REPO%\.hg" (
    goto onlyremote
) else If exist "%LOCAL_REPO%\.hg" (
	goto onlylocal
) else (
	goto missingonboth
)

 
 
 
:Remoteandlocal
Echo File exist remote and local
c:
cd %LOCAL_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "update from %COMPUTERNAME%"
hg pull %SSH_REPO%
hg merge -t "W:\scripts\merge_other.bat"
hg resolve -t internal:local --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg push  %SSH_REPO%
echo "remote update start"
ssh %USERNAME%@sfs "/scripts/hgsync_logout.sh"
echo "remote update end"
hg pull  %SSH_REPO%
hg update
goto END

:onlylocal
Echo File exist only local
c:
cd %LOCAL_REPO%
echo "remote init start"
ssh %USERNAME%@sfs "/scripts/hgsync_init.sh"
echo "remote init end"
hg addremove
hg --config ui.username=%USERNAME% commit -m "update from %COMPUTERNAME%"
hg push  %SSH_REPO%
echo "remote update start"
ssh %USERNAME%@sfs "/scripts/hgsync_login.sh"
echo "remote update end"
hg pull  %SSH_REPO%
hg merge -t "W:\scripts\merge_other.bat"
hg resolve -t internal:local --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg push %SSH_REPO%
echo "remote update start"
ssh %USERNAME%@sfs "/scripts/hgsync_update.sh"
echo "remote update end"
goto END

:onlyremote
Echo File exist only remote
c:
cd %LOCAL_REPO%
hg init
hg pull  %SSH_REPO%
hg addremove
hg --config ui.username=%USERNAME% commit -m "update from %COMPUTERNAME%"
hg merge -t "W:\scripts\merge_other.bat"
hg resolve -t internal:local --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg push %SSH_REPO%
echo "remote update start"
ssh %USERNAME%@sfs "/scripts/hgsync_update.sh"
echo "remote update end"
goto END

:missingonboth
Echo missing on both
mkdir %LOCAL_REPO%
C:
cd %LOCAL_REPO%
hg init
echo "remote init start"
ssh %USERNAME%@sfs "/scripts/hgsync_init.sh"
echo "remote init end"
hg addremove
hg --config ui.username=%USERNAME% commit -m "update from %COMPUTERNAME%"
hg push %SSH_REPO%
echo "remote update start"
ssh %USERNAME%@sfs "/scripts/hgsync_logout.sh"
echo "remote update end"
hg pull %SSH_REPO%
hg merge -t "W:\scripts\merge_other.bat"
hg resolve -t internal:local --all
hg update
hg addremove
hg --config ui.username=%USERNAME% commit -m "merge update from %COMPUTERNAME%"
hg push %SSH_REPO%
echo "remote update start"
ssh %USERNAME%@sfs "/scripts/hgsync_update.sh"
echo "remote update end"
goto END

:END
echo done
windows/hgsync.1634758886.txt.gz · Last modified: 2021/10/20 14:41 by tschulz