Compare files stored on svn with files on local drive - powershell

I am trying to write a script on PowerShell that will compare svn files with local files and then to display the files that have changes. I would like also to display files name that exist on local drive but not on svn location.
My code is:
$list1 = (svn list C:\Users\name\Desktop\Workingfiles\)
foreach ($thisFile in $list1){
Write-Host $thisFile
$var = (svn diff C:\Users\name\Desktop\Workingfiles\$thisFile svn://server/files/Users/name/$thisFile )
# Write-Host $var
}

You can use the svn diff command with --old and --new options. However, it seems that you can not diff repository item with a local unversioned one. You should be able to diff a file from working copy with unversioned file, though.
But what about writing repo file's content into a file? Here is an example:
svn cat URL-TO-FILE > file-from-repo.txt
svn diff --old file-from-repo.txt --new local-file.txt

Related

Execute "SVN Copy Versioned Items Here" within Powershell

Within a PowerShell script I need to do the following:
Execute the "SVN Copy Versions Items Here" RMB command for copying an earlier version of File A to a later version of File A in order to compare the before / after prior to a commit.
I know the full path of both files, and the paths / call look something like this:
$fromFile = C:\trunk\v100\fileA.txt
$toFile = C:\trunk\v200\fileA.txt
If I execute the following command:
svn copy $fromFile $toFile
I get the following error: svn: E155010: Path 'C:\trunk\v200\fileA.txt' is not a directory
I believe $fromFile and $toFile are both stored as text.
Any suggestions?
I was able to figure this out. Posting solution in the event anyone comes across the same issue. The error message displayed was a red herring - it has nothing to do with a directory.
Note: In my example, the $toFile had been added via a Subversion Add.
Resolved in the following manner:
svn revert $toFile
Remove-Item $toFile
svn copy $fromFile $toFile
It seems like if the file is present an error is thrown. The revert and remove calls fixed this.

Load file from GitHub in PowerShell

I have written a PowerShell script which loads a json file and performs certain function on it. I am using:
$json = Get-Content 'C:\Users\Documents\test.json' | Out-String | ConvertFrom-Json
to load the file which works. But I want to store both these files in a git hub repository. How can I access the json file path once I store both the files in the same directory in a GitHub repository?
I am new to using GitHub so any help would be appreciated.
If you want to work with a remote path, you can use the webclient to download the file as a string and convert it using the ConvertFrom-Json cmdlet:
$jsonPath = 'https://raw.githubusercontent.com/jaypat/documents/master/test.json'
$json = (New-Object System.Net.WebClient).DownloadString($jsonPath) | ConvertFrom-Json
You might need to either use the Github API or commit and push using git. For the latter you should do something like the following from the local git repository:
git add test.json
git commit -m "Message for what changes you've made"
git pull
git push origin master
It'd be really helpful if you first read and understood what git is and how it works. Then you'd be ablt to use github seamlessly. Here is a great interactive tutorial for it: https://try.github.io/levels/1/challenges/1
I ended up using path binding to reference the file
$path = join-path $psscriptroot "env.json"
This sources to the directory where all the files are loaded.

How to copy files in svn into a new directory that depends on a variable value?

I'm currently writing a script in PowerShell which calculates a new tag in the tag directory. I want to copy files from one SVN directory to another directory that depends on the new tag number I calculated.
Here are the lines from the script:
$tag = Write-Host "$($svnMavenTagPrefix)$($nextMavenTagVersion)"
svn copy http://tlvsvn1/svn/repos-bls/MassAnalytics/trunk/ http://tlvsvn1/svn/repos-bls/MassAnalytics/tags/${tag}
For some reason it doesn't work and I receive the following error:
svn: E205007: Could not use external editor to fetch log message; consider setting the $SVN_EDITOR environment variable or using the --message (-m) or --file (-F) options
svn: E205007: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and no 'editor-cmd' run-time configuration option was found
How can I copy the files to a new tag?
The Write-Host cmdlet prints the string you are passing as an argument but doesn't write anything to the output thus $tag is empty. I would recommend you to use a format string:
$tag = '{0}{1}' -f $svnMavenTagPrefix, $nextMavenTagVersion
$url = 'http://tlvsvn1/svn/repos-bls/MassAnalytics/tags/{0}' -f $tag
svn copy http://tlvsvn1/svn/repos-bls/MassAnalytics/trunk/ $url

Generate Hg diff (or patch) that Only includes content for files modified by a revision/revset

Given a large codebase and two revisions or revsets (say, a local 'source' and a target) which may or may not share a recent parent and usually contain a large number of non-relevant file deltas;
How can diff output be generated to compare the changes only for files that are modified in the source revset itself?
(This should be the delta between the ancestry; but only for the files contained within the revset.)
Using hg diff -r target -r source shows all the changes in the ancestry, even for files not modified by the source sevision.
In addition, this should be done without any knowledge of the directory structure.
If I understand correctly, you want a diff between revs source and target, but you want to restrict it to the files that were modified in changeset source. You can do it in two steps (easily assembled into one with an alias or shell script):
List the files modified in source:
hg log -r source --template '{files}'
This just outputs a list of filenames.
Request a diff for these files:
hg diff -r target -r source $(hg log -r source --template '{files}')
Step 2 is a bash command with "command substitution" $(...), which inserts the output of step one. Other methods are possible.
From hg help diff
If only one revision is specified then that revision is compared to the working directory
i.e. you can try hg up $SOURCE; hg diff -r $TARGET

how to alias the current folder

How can I alias the output of this command?
[basename "$PWD"]
I basically want to be able to to do
git browse [basename "$PWD"]
You can run this directly: git browse "$(basename $PWD)"
Or, you could alias it:
alias browsepwd='git browse "$(basename "$PWD")"'
Or, you could write a bash function
function bnpwd() {
basename $PWD
}
Then you can run git browse "$(bnpwd)".
Or any combination of the above ;)
I'm not familiar with git browse, but I suspect what you want is this:
git browse .
Your original concept seems a little flawed to me for this reason - suppose my git repository is in /usr/local/projects/widgets. If I cd /usr/local/projects/widgets, then $PWD will be /usr/local/projects/widgets, and basename $PWD will report widgets. Unless my project has a subdirectory widgets, git browse $(basename $PWD) probably isn't right, and even if such a subdirectory does exist, I would guess the result wouldn't be exactly what is expected. On the other hand, depending on exactly git browse does with its arguments, git browse . is probably essentially equivalent to git browse $PWD. They at least reference the same directory.