I want to clone selected folder(s) from my repository and don't want other folders to be downloaded when cloned. I am using libgit2sharp APIv0.24.0.
Reference image
Thanks in advance.
You cannot only clone a select set of folders, but you can only checkout a select set of folders.
You will need to clone the entire repository - as of now, the Git protocol has no ability to do a "narrow" clone, where you only clone a select set of files or folders.
However, you do not need to check out the entire repository. You can ask clone to not do the checkout for you, then check out only the folders you are interested in.
For example:
string path = Repository.Clone(url, localpath, new CloneOptions()
{
Checkout = false
});
using (var repo = new Repository(path))
{
repo.CheckoutPaths("origin/master", new string[] { "Model" });
}
Related
Here is my requirement.
I want to use the Jenkins for packaging multiple zip files.
We have an artifactory with repo A and repo B -- Each one of them have multiple zip files. I have the api's to list the files of a repo
In Jenkins, I want to create a parameterized job where 1st parameter should be able to populate list of zip files from Repo A and 2nd parameter should be able to populate list of zip files from Repo B + In 2nd parameter i should be able to select multiple zip files populated from Repo B
Can you please suggest a better way to do this.
Try something like it:
List<String> files = populate()
doSomething(files)
List<String> populate() {
List<String> files = ''
if (JOB_PARAMETER == 'repoA') {
files.add(yourApiCall())
} //similarly for another
return files
}
JOB_PARAMETER is a parameter in your Jenkins job
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
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.
I'm redesigning a control that lists the contents (files and folders) under a given TFS path. The tricky part is that I don't want to create a workspace for achieving this, as my intention is just to list the contents and display the history of a selected item. The current implementation creates a local workspace mapping in the background to achieve this, is this needed? Can I attain this without a local workspace mapping?
Thanks
Joe.
Use GetItems, which does not require a workspace. For example:
TeamFoundationServer tfs = new TeamFoundationServer("http://tfs:8080/tfs/DefaultCollection");
VersionControlServer versionControl = tfs.GetService<VersionControlServer>();
ItemSet items = versionControl.GetItems(tfsPath, RecursionType.Full);
I'm trying to make job in Jenkins, that make build any of tags, trunk, branches.
These parameters I added
Choice Parameter named SRC_TYPE with choises tags, branches, trunk
List Subversion tags named PROJECT_TAG with repository URL svn://foo/bar/tags
List Subversion tags named PROJECT_BRANCH with repository URL svn://foo/bar/branches
Now I'd like to add module (subversion) to section Source Code Management that depends on parameters.
I need to set repository URL for this module to
svn://foo/bar/tags/${PROJECT_TAG}/Project for ${SRC_TYPE} == "tags"
svn://foo/bar/branches/${PROJECT_BRANCH}/Project for ${SRC_TYPE} == "branches"
svn://foo/bar/trunk/Project for ${SRC_TYPE} == "trunk"
Is it possible? And how it can be done?
You need version 1.32 of the subversion plugin, as it fixes ISSUE-10678
Once you have that, you can configure Subversion Drop-Down Build Parameter, provide the SVN URL of http://foo/bar and it will list trunk, all branches, and all tags under the dropdown.