Choosing prefix name on creating new branch - tfs

In our company, we use azure-devops and edited some settings about folder hierarchy (hotfix, feature, bugfix etc.) with this documentation.
We want to choose one of those prefix names and type branch name. For example, I choose feature and type login-page. Branch name will be hotfix/login-page.
I search a lot but don't any result about that. Is there any way to do that?

I choose feature and type login-page. Branch name will be
hotfix/login-page.
If you mean creating a branch name such as hotfix/login-page, then it's not supported. We can only select based on branch but cannot select the folder, that means we cannot create a branch based on a folder.
In your scenario, it will create a new branch called login-pagebranch under the hotfix folder.
That means / here will be identified as the symbol of the folder hierarchy.
If you want to create a branch under the feature folder, then you should type feature/login-page. We cannot select prefix name on creating a new branch.

Related

How to add a branch-type tag to a previously created branch in Bitbucket?

When I create a new branch through Bitbucket I have the possibility to tag the new branch. If I tag it as "Feature", then the branch will start with "feature/".
What if I already have branches that start with "feature" but they have no tag? Could I add the "Feature" tag to them?
Are you talking about the "Branch type" field (Bugfix, Feature, Hotfix, etc) in the "Create branch" dialog?
If yes, there's no difference between a branch created with branch type "Feature" and another created with branch type "Custom" if it has the "feature/" prefix. You don't need to add any "tag" to it (you can't actually).

How to restrict branch creation based on pattern in Bitbucket

I am using Atlassian Bitbucket server v4.8.6.
How do I restrict restrict branch creation based on pattern.
Rules explained below -
Only ABC team should be able to create release/ABC-*
Only XYZ team should be able to create personal/XYZ-*
You can't create rules to prevent only the "creation" of branches. These are the avaliable restrictions:
Prevent all changes
Prevent deletion
Prevent rewriting history
Prevent changes without a pull request
To create branch permissions do the following:
Go to Repository > Settings > Branch permissions > Add permissions
Select "Branch pattern"
Add branch pattern, ex: release/ABC-*
Select one of the restrictions available
Add the group exception, ex: ABC
This can be done by adding "*" on Select branch text field. See the screenshot below.
Go to your repository > Settings > Branch permissions > Add permission
Under "Select branch - By name or pattern", put an asterisk (*)
Save
After that, you can restrict each branch patterns you want for different teams or people.
ABC group
Select branch = release/ABC-*
Write access = ABC group or ABC members
Personal branch
Select branch = personal/XYZ-*
Write Access = Your account

Include branch name in post build event on Team Build

I would like to perform the following steps in the TFS build process:
do post build event that will copy some files from my compiled projects to another predefined directory, I'd like that directory path to include the branch name.
I'd like to be able to refer to the branch name inside my xaml workflow template as well.
The first one is rather simple. When you're using the new TFS 2013 build server and process template, you can simply add a post-build powershell script in the Build Definition Configuration, check in the script and run it during the build.
The second one is dependent on whether you're using TFVC or Git, in the first case, use the VersionControlServer class to query the BranchObjects, then check which one is the root for your working folder. Be aware though, that in TFVC multiple branches can be referenced in one workspace, so there may be multiple answers to this query, depending on which file you use the find the branchroot. A custom CodeActivity would do the trick, similar to this check in a custom checkin policy.
The code will be similar to:
IBuildDetail buildDetail = context.GetExtension<IBuildDetail>();
var workspace = buildDetail.BuildDefinition.Workspace;
var versionControlServer = buildDetail.BuildServer.TeamProjectCollection.GetService<VersionControlServer>();
var branches = versionControlServer.QueryRootBranchObjects(RecursionType.Full);
var referencedBranches = listOfFilePaths.GroupBy(
file =>
branches.SingleOrDefault(
branch => file.ServerItem.StartsWith(branch.Properties.RootItem.Item)
)
).Where(group => group.Key != null);
To get a list of all items in yo workspace, you can use Workspace.GetItems.
In case you're using Git, you have a few options as well. The simplest is to invoke the command line:
git symbolic-ref --short HEAD
or dive into LibGit2Sharp and use it to find the branch name based on the current working folder from a custom activity.
If you want to include this in an MsBuild task, this may well be possible as well. It goes a bit far for this answer to completely outline the steps required, but it's not that hard once you know what to do.
Create a custom MsBuild task that invokes the same snippet of code above, though instead of getting access to the workspace through BuildDetail.BuildDefinition.Workspace, but through the WorkStation class:
Workstation workstation = Workstation.Current;
WorkspaceInfo info = workstation.GetLocalWorkspaceInfo(path);
TfsTeamProjectCollection collection = new TfsTeamProjectCollection(info.ServerUri);
Workspace workspace = info.GetWorkspace(collection);
VersionControlServer versionControlServer = collection.GetService<VersionControlServer>();
Once the task has been created, you can create a custom .targets file that hooks into the MsBuild process by overriding certain variables or copying data when the build is finished. You can hook into multiple Targets and define whether you need to do something before or after them.
You can either <import> these into each of your projects, or you can place it in the ImportAfter or ImportBefore folder of your MsBuild version to make it load globally. You can find the folder here:
C:\Program Files (x86)\MSBuild\{MsBuild Version}\Microsoft.Common.Targets\ImportAfter

TFS API Create Branch Programmatically visualization

I have a folder into tfs,and I want to take branch of this folder with creating new folder and put branch under this new folder programmatically.Normally when we do it in tfs it automatically change folder to branch.
When I use createbranch command ,it works ,create folder and under these new folder it create new branch,but branch seen like folder in tfs but I can merge it vs so it is working.If I want to change visualization I have to use second command CreateBranchObject.Is it possible to that in one command
Folder A-->take new branch
Folder A'(New Folder) --> Branch
Code Sample
int changesetId = VersionControlServer.CreateBranch(#"myfolder ", "mynewfolder\newbranch",
VersionSpec.Latest);
Changeset changeset = vcs.GetChangeset(changesetId);
changeset.Update();
This is not like in a single command and you will need to call both in sequence.

Git merge from a specific folder only

I've created a rails website for client X. I now have a client, Y, who wants a website that does the exact same thing as client X, but with a different skin.
I made a git branch from clientXcode and called it clientYcode. I then did all the changes to the views to make it look different, and lala, the same website with a different skin.
Now here's what I don't understand about git: I've made many changes to clientXcode in the views, models, and controllers; and now I want to merge those changes into clientYcode, excluding any view changes. Since views, models, and controllers each have their own folder in rails I was hoping to be able to do something like:
git merge client_x_code 'app/controllers/*', 'app/models/*'
QUESTION 1: Is something like that possible with git? If so, how would I do it?
QUESTION 2: Was branching the best solution to make a copy of my project?
Well I found the easiest solution to my problem...
git checkout clientYcode
git checkout clientXcode "app/controllers/"
git checkout clientXcode "app/models/"
And that does what I want!
The simplest course of action is to merge everything, except the content of the directory you want to keep.
You can do that by adding a merge driver in that directory, as the How do I tell git to always select my local version for conflicted merges on a specific file? question details.
With that merge driver in place, Branching is a good solution in this case.
Extract:
We have a .gitattributes file defined in the dirWithCopyMerge directory (defined only in the branch where the merge will occurs: myBranch), and we have a .git\config file which now contains a merge driver.
[merge "keepMine"]
name = always keep mine during merge
driver = keepMine.sh %O %A %B

Resources