How to write a batch file for svn commit and update - windows

so far I have used Tortoise SVN to commit and update folders under version control. When I commit I check "all" in the GUI dialog so that deletions as well as additions are committed.
Now I have more and more folders under version control and I would like to have a batch file for committing and updating all of them.
So far I have experimented with the command line and found this:
svn add . --force
svn commit -m"Adding missing files"
This adds new files but does not reflect any deletions.
Could you please help me with the batch files? It would make my work a lot easier but I am really too unexperienced with SVN/batch files to do this on my own...
I use Win7x64 and Tortoise SVN 1.7.12 with the command line extension.
Thank you!

I think I figured something out using gammay's and this input:
cd "C:\Users\User\Desktop"
for /f "usebackq tokens=2*" %%i in (`svn status ^| findstr /r "^\?"`) do svn add "%%i %%j"
for /f "usebackq tokens=2*" %%i in (`svn status ^| findstr /r "^\!"`) do svn delete "%%i %%j"
svn commit -m "Commit via Batch"
And
cd "C:\Users\User\Desktop"
svn update
and repeatedly for different paths!
Thank you :)

Firstly, which svn command line tools do you use? You can use CollabNet for 'svn' commands.
Secondly, to delete files, you need to checkout existing files from svn, then use svn delete and then svn commit.
Your question is not clear - if this doesn't answer your question, please provide a few more details.
Edited to answer asker's requirement (in comments below):
OK. What you want is a script which will find the new files in the folder and add them to SVN automatically and find deleted files in folder and delete them from SVN too. I can tell you this is a dangerous as undesired files can get added/deleted.
Still, if you want to go ahead with this script this is what the script can do:
Run svn status which displays missing (deleted) files and unknown (to be added) files
! FileA [Missing - deleted]
? FileD [Unknown - to be added]
Parse the output to find the ! files and run svn delete on these files
svn delete FileA
Parse the output to find the ? files and run svn add on these files
svn add FileD
svn commit
This commits the above deleted & added files and also any modifications.
If you do not want to commit modifications, commit individual added/deleted files

Related

List all Mercurial repositories cloned under a folder

I have a C:\Dev folder, where I have cloned multiple Mercurial repositories. How do I get a list of those, so I can then clone them on a different PC?
You will probably have to write a batch script to do that and then use the hg paths default in each directory.
Put the something along those line in a new .bat file and then run it in your C:\Dev directory :
FOR /D %%G in ("*") DO hg -r %%G paths default
It is been a long time since I didn't wrote a batch file and I don't have a Windows machine to test it on, so it may need some modifications in order to work.
Good luck !

Which tool will allow me to merge multiple folders in a single folder based on modification date

I need to merge multiple (more than two) folders that have a similar tree and file structure
For example if I have these folders
FolderA/DB/A.SQL - last modified: yesterday
FolderA/DB/F.SQL
FolderA/WebSite/one.aspx - last modified: today
FolderB/DB/A.SQL - last modified: today
FolderB/DB/C.SQL
FolderB/WebSite/one.aspx - last modified: yesterday
FolderB/WebSite/two.aspx
FolderC/DB/B.SQL
FolderC/WebSite/three.aspx
The merged single folder should contain
Merged/DB/A.SQL - last modified: today (taken from FolderB)
Merged/DB/B.SQL
Merged/DB/C.SQL
Merged/DB/F.SQL
Merged/WebSite/one.aspx - last modified: today (taken from FolderA)
Merged/WebSite/two.aspx
Merged/WebSite/three.aspx
Which tool will allow me to do this ? Winmerge only merges TWO folders. And I need to merge any number of folders (not just 3 like in the example) and each folder can contain multiple files
I am asking this because if the tool does not exist I will write it on my own but I rather use the wheel than reinvent it
Apparently most of the tools out there work on two folders or they merge the files but dont keep the folder structure and many version cost money but dont perform the exact task that I need.
I have already to develop this, if any one needs this tool let me know I will share it
How about any version-control tools like: SVN, Git or whatever else:
With git you can init empty repository locally and commit 1st folder into.
Than copy over the 2nd folder replacing the files. Then in commit dialog - review changes, revert if previous (which already in repo) file state changes had higher priority.
Commit the new state.
Repeat steps 2-3 for any number of such folders.
I'm using these technique when merging complex folder structures which are not version controlled and got simultaneous changes for some reason.
I wasted half an hour on RichCopy (not feasible for two thousands folders) and PowerShell (too complicated) before I fall back to xcopy:
In command prompt, go to the folder containing FolderA, FolderB, FolderC etc.
Run md Merged to create destination folder.
Run xcopy in a for loop:
for /D %%i in (*) do xcopy "%%i" Merged\ /e /h /d /y
Breakdowns:
for /D %%i in (*) do - repeat for each directory.
xcopy "%%i" Merged\ - copy directory contents to "merged" folder.
/e - copy recursively, including empty directory.
/h - don't skip hidden and system files.
/d - overwrite only if newer.
/y - don't ask, just overwrite.

Programmatically (not manually) finding the path where Git is installed on a Windows system

I'd like to write a small build helper tool that shall read some properties of the current Git working directory, like the last commit hash, whether there's modified files and so on. I found that it is easier to use the installed Git binaries instead of reading the .git directory with its compressed files in an unknown format. But my tools must be as portable as possible. It's intended for .NET applications, so the only requirement should be .NET 2.0 or newer.
Now how can I find the path where Git is installed? There's a default one that is used if the user has just clicked through the Git installer. But it may be different. And when I see all the programme files in git/bin, I really don't want that to be in my %PATH% (which other tools like TortoiseGit don't seem to require, too). I haven't found any path clues in the registry.
What algorithm could I use to find Git, that is not a full file system scan? (Did I already say it needs to be fast?)
If you are inside of (or if you can open) your git bash shell, you can use pwd -W
$ cd / && pwd -W
C:/Program Files (x86)/Git
(I know, this is probably not what you want, and it's quite elementary, but I spent some time to find this, and perhaps it's useful for other people).
I'm using the following batch file to find out where Git for Windows has been installed:
#echo off
setlocal enabledelayedexpansion
rem Read the Git for Windows installation path from the Registry.
for %%k in (HKCU HKLM) do (
for %%w in (\ \Wow6432Node\) do (
for /f "skip=2 delims=: tokens=1*" %%a in ('reg query "%%k\SOFTWARE%%wMicrosoft\Windows\CurrentVersion\Uninstall\Git_is1" /v InstallLocation 2^> nul') do (
for /f "tokens=3" %%z in ("%%a") do (
set GIT=%%z:%%b
echo Found Git at "!GIT!".
goto FOUND
)
)
)
)
goto NOT_FOUND
:FOUND
rem Make sure Bash is in PATH (for running scripts).
set PATH=%GIT%bin;%PATH%
rem Do something with Git ...
:NOT_FOUND
I should be straight forward to do something similar in .NET. Just remember that you have to explicitly check the 32-bit branch of the Registry if you're on a 64-bit Windows.
Edit: Git for Windows 2.6.1 now additionally writes the CurrentVersion, InstallPath and LibexecPath values to the HKEY_LOCAL_MACHINE\Software\GitForWindows key.
If you are in Windows 8 and above here are the steps that you can follow.
go to your start screen and search for git.exe
In the search result right click on the Git Gui/ Git Bash icon and select Open File location
You will be taken to a flder where the shortcuts will be located. Right click on the shortcut nd select properties
the file location can be found in the Target field
For me it was "C:\Users\\AppData\Local\Programs\Git\cmd\git-gui.exe"
Hope it helps
You can also open Git Bash and type where git. It will return the path where Git is installed on your machine.
git --man-path gets you to [base git installation dir]\mingw64\share\man. git.exe is at [base git installation dir]\cmd.
look in the registry under: HKEY_CURRENT_USER\Software\Git-Cheetah
Ancient question, but if you're installing git through through the standard installer, one way to get where its installed is by asking the registry:
In powershell:
(Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\GitForWindows).InstallPath
This returns:
C:\Program Files\Git

Why would a post-build step (xcopy) occasionally exit with code 2 in a TeamCity build?

A few projects in my client's solution have a post-build event: xcopy the build output to a specific folder. This works fine when building locally. However, in TeamCity, I occasionally get
xcopy [...] exited with code 2
If I use regular copy, it exits with code 1. I expect this has something to do with file locks, although the specific files being copied are not the same, so perhaps just locking on the shared destination directory. I use /y to not prompt on overwriting files.
Why this fails in TeamCity but not locally?
Even if you provide the /Y switch with xcopy, you'll still get an error when xcopy doesn't know if the thing you are copying is a file or a directory. This error will appear as "exited with code 2". When you run the same xcopy at a command prompt, you'll see that xcopy is asking for a response of file or directory.
To resolve this issue with an automated build, you can echo in a pre-defined response with a pipe.
To say the thing you are copying is a file, echo in F:
echo F|xcopy /y ...
To say the thing you are copying is a directory, echo in D:
echo D|xcopy /y ...
Sometimes the above can be resolved by simply using a copy command instead of xcopy:
copy /y ...
However, if there are non-existent directories leading up to the final file destination, then an "exited with code 1" will occur.
Remember: use the /C switch and xcopy with caution.
I fixed the error code 2 by adding a \ at the end of my path, without it, xcopy will think that it is a file instead of a folder.
If you are using xcopy in a post build event use the /Y switch in addition to the /C.
/C Continues copying even if errors occur.
/Y Suppresses prompting to confirm you want to overwrite an existing file.
My fix for this issue was to go into the target bin folder, and ensure that the proper subfolder exists there. Once that subfolder was manually created, the build process completed successfully.
copy fixed it for me. xcopy with /c /y did not work. I was getting an exit 4 so I went with xcopy, but turned out I needed quotes around ($TargetPath).
My script:
if $(ConfigurationName) == Debug copy "$(TargetPath)" "$(SolutionDir)\Folder\bin\Debug\$(TargetFileName)"
Probably you using TeamCity with git. If yes, check that folders you want to copy are exists in git repository. Usually git aviod adding empty project folders to repository, so xcopy fails to find it and generates a error.
You can add some empty text file to empty folder, commit and see folder appears in repository.

Subversion; checking out only trunk for multiple projects

I have a directory structure in svn like this:
Project A
branches
tags
trunk
Project B
branches
tags
trunk
...
I want to checkout only trunk directories for all these projects. There are about 400 of these kind of projects so checking out trunk manually won't be an option.
My first guess would be to use svn list, but my shell scripting skills are not up to par and I'm sure how to create the appropriate directories and append 'trunk' and do a checkout.
Anyone willing to point me in the right direction?
TL:DR;
svn list produces something like 'project_a'.
I want to checkout 'project_a/trunk' into 'project_a'.
You can store the list of projects to a file (projects_list), then run this script:
for p in $(cat projects_list); do
mkdir $p
svn co "$url/$p/trunk" $p
done
Here is a way to do it by using the depth flag:
echo Getting Projects the folder structure
svn co http://www.therepo.com/projectsParentFolder --depth immediates
echo Getting the structure for each Project
for /f %%f in ('dir /b .\projectsParentFolder') do svn co http://www.therepo.com/projectsParentFolder/%%f .\projectsParentFolder\%%f --depth immediates
echo Getting the trunk for each Project
for /f %%f in ('dir /b .\projectsParentFolder') do svn co http://www.therepo.com/projectsParentFolder/%%f/trunk .\projectsParentFolder\%%f\trunk --depth infinity

Resources