Libgit2sharp how to do a mirror push - push

I am fairly new to Git/LibGit2Sharp and am trying to create a mirror of a git repository using LibGit2Sharp. Following the directions given here: https://github.com/libgit2/libgit2sharp/issues/577, I first mirrored the external repository to a local folder by adding a remote to it, and used repo.Network.fetch(remote, fetchRefSpec) where fetchRefSpec is refs/\*:refs/*
Now, I want to push the data to another remote repository. Here I am confused. Because, when doing this through git commands, you set the remote.remoteName.mirror config entry to true and then do git push remoteName. Specifying any other refSpec when mirror is set to true gives an error.
However, when using LibGit2Sharp, even after I set mirror = true, I still have to provide a pushRefSpec while pushing. Providing empty or wildcard refSpecs throws exception. I even tried refs/tags/\*:refs/tags/*, but I got the same exception. Looping through all branches in the pushRefSpec works, but does not create a mirror.
Has anyone tried this? Is there probably a better way to do this?

The .mirror configuration is an option for the git tool. libgit2(sharp) works at a different level, where you need to specify exactly what you want to push.
At the moment it unfortunately does not support refspecs with a pattern on push, so if you want to push every reference, you'll have to add each of them individually as refspecs for the push.

Related

Is there a way to configure a local mercurial repository to stop it from being able to push to a remote repository?

In git, there is a common practice of removing push access to the upstream repository for teams which use a specific workflow. This can be accomplished with a simple command to change the configuration. This keeps developers from accidentally pushing up changes without the proper review process. It still allows users to pull the latest changes from that repository.
Is there a way to configure a local mercurial repository to stop it from being able to push to a remote [read-only] repository?
You have at least two ways: local and remote
Remote-repo type
On push-target add pretxnchangegroup hook, which reject pushes (all or some), easiest form
#!/bin/sh
echo 'No pushes here'
exit 1
Local type
Add alias, which redefine push into "something" without real push, but note the note in docs
It is possible to create aliases with the same names as existing
commands, which will then override the original definitions. This is
almost always a bad idea!

How do I get a new branch to show up in Eclipse Git Remote Tracking?

I have an existing Eclipse git project, with a master and development branch present in both local, and remote tracking. I have just added a new branch in my git repository, but I can't figure out how to get it to show up in Eclipse.
I have tried to read up on the subject, but it seems like it is just expected to automatically show up. I have found a lot of similar questions, but they all seem to deal with the issues of a completely empty remote tracking folder, instead of my problem of only a single new branch missing. I already have Master and Develop present.
Here is what does not work:
Clicking refresh in the Git repositories window.
Any kind of synchronize, pull or other update I can find
Here is what would work:
Right clicking the remote tracking folder, and selecting "Paste repository path or URI". If I do that, and select the exact same path as is already there, I can see my new branch. This action does require that I completely clone the whole repository to an empty folder again, and that can't be how this is intended to work.
I believe it might work to use some kind of command line tool, but I really want an Eclipse solution to this, as I feel sure it exists, and I am just missing something.
In the Git Repositories view:
Right-click the repository and choose Fetch from Upstream
If the new branch will not shown up below Branches/Remote Tracking, you have to configure fetch:
Right-click the fetch node below Remotes/origin and choose Configure Fetch...
In the Configure Fetch make sure there is only the single Ref mapping (assuming the remote is named origin) +refs/heads/*:refs/remotes/origin/*:
In case you do not see Fetch from Upstream after right-click the repository, you may look for Fetch from origin.
For me the solution was almost what Joshua suggested, however it did not work as described. For me the solution was to configure the [remote "origin"] property as follows:
[remote "origin"]
url = your_git_url.git
fetch = refs/heads/*:refs/remotes/origin/*
Alternatively, you can do it from the Eclipse UI too:
Fetch from origin... then hit Configure... and in the configuration window hit Advanced... and there you have the option to Add predefined specification where you can selec Add All Branches Spec. This will result in the same configuration as above:
Maybe you have to remove your original entry which will be pointed out as a duplicate by Eclipse.
You need to modify the "config" file in your local git repository folder. For example, you cloned a remote branch Project into c:\git\MyProject local folder. In this folder there is a hidden folder ".git" that has a "config" file. There is a section in this file resembling the below
[remote "origin"]
url http://xxxxxxxxxxxxxxxx
fetch = +refs/heads/Project:refs/remotes/origin/Project
You need to modify this section as below
[remote "origin"]
url http://xxxxxxxxxxxxxxxx
fetch = +refs/heads/:refs/remotes/origin/
Then go back to Eclipse IDE, right click on the repository and do a "fetch from origin". Now all the branches will show up.
What I did:
1: disconnected.
2. refresh and pull. Then, it shows the new branch
3. create local and pull.

How can I copy an git repository in Xcode to github?

Every time a try to use github I get tangled in a series of errors that seem to have no solution and I give up. This time I thought I'd try to get help.
I have a local repository created and managed with Xcode. All the local git functions in Xcode work with no problem. Now I want to put this project on github so others can see it. I logged into github and created a repository. It's this one:
lummis/CS193P-2015-Assignment-5
I added a .gitignore file but then deleted it again because I thought it was causing an error. I tried adding a readme file but wasn't able to. I got some error that didn't make sense to me so I gave up on that. So at this point the github repository is empty so far as I can tell.
My local repository has many commits and is currently up-to-date. IOW there is nothing to commit. But when I do "Source Code / Push" I get the following error:
Working copy out of date. Try pulling from the remote to get the
latest changes then push again.
So I try to do that in Xcode by doing "Source Control / Pull". But then I get this error:
"github/master" is not a valid remote branch to pull from. Please
choose a different remote branch.
But there is only one branch. There is no other branch (local or remote) to choose. So I'm stuck in a Xcode-github error loop again. I searched for information about this but didn't find anything relevant. I have the Pro Git book and read and understood it at least thru chapter 2. But that doesn't help on interacting with Xcode.
Can anybody say what I need to do? I thought of deleting the remote repository and starting over but apparently there's no way to do that either!
I know lots of people use github so it must work once you know how to use it but it's a big source of frustration for me.
You have a local repository with "many commits". Let's imagine that we have three:
A---B---C
^
master
Your remote repository on GitHub also contains commits, but they are different ones from what you have locally, e.g.
Y---Z
^
master
At least one of these remote commits was created through the GitHub web interface, which creates a new commit each time you use it.
Because the two repositories contain no common history, Git can't figure out how to handle a push from your local repository to the remote one. It will refuse to accept such a push rather than making any remote commits inaccessible, which is what you usually want.
In this case, commits Y and Z in the remote repository can be discarded. They simply add and then remove a .gitignore file, and you want the remote to reflect what you have locally. The solution is to force push.
Force pushing should generally be avoided, since it can cause commits to be discarded (like Y and Z will be in this case) or to have their hashes changed, which causes major problems with shared repositories. In this instance I don't see any danger in force pushing, which can be accomplished with the -f or --force argument to git push.
(There's nothing fundamentally wrong with force pushing, and in some situations it makes perfect sense, but it should be done with care for the reasons listed above.)

Buildbot fails on reset --hard

Buildbot 0.8.6
Periodically the buildbot would fail getting a particular repository. It does this command:
argv: ['/usr/bin/git', 'reset', '--hard',
'26d7a2f5af4b777b074ac47a7218fe775d039845']
and then complains:
fatal: Could not parse object
'26d7a2f5af4b777b074ac47a7218fe775d039845'.
However, the correct command is actually:
argv: ['/usr/bin/git', 'reset', '--hard', 'FETCH_HEAD']
Not only that. The SHA number used in the failed command is from a different repository.
Anyone knows how to fix this?
Thanks so much.
Update:
We have two repositories. We have a GitPoller watching one of the repositories. I would like to have a build run if the watched repository had a push. However, both repositories are needed for the build. The error specified above occurs on the second, non-watched repository. The SHA number in the error is from the watched repository.
Ok, first, let's make sure we have the right understanding:
You're having problem with one builder, that builds 2 repositories
Each build has two git steps which clone two different repositories
You're polling one of these repositories to trigger builds
There is no other scheduler that is triggering builds (or at least not those that fail that way)
What happens when you're polling a repository to trigger builds is that each new build carries with it the changes that triggered it. The git steps refer to these changes to checkout the correct version. You probably need to use codebases to help the two steps distinguish between changes. Unfortunately, codebases were introduced in 0.8.7, so you should consider upgrading. 0.8.6 is ancient.
If upgrading is not an option, pass alwaysUseLatest=True to the Git() step of the repository that you are not polling. That will force it to always use FETCH_HEAD. Here's my shot at that setup:
f = BuildFactory()
f.addStep(Git(repourl='git://github.com/you/polled_repo.git', mode='copy'))
f.addStep(Git(repourl='git://github.com/you/other_repo.git', alwaysUseLatest=True))

Eclipse Egit not picking up configured remote repository

I have since upgraded to Juno and the latest version of Egit. However, i noticed that when i attempt to push to a remote repository, the configured remote repository is defaulting to some random repository URL that isn't associated with my repository. the configured one seems to be picked up from some other location. has anyone seen this behavior? i checked my repository and see the proper remote URL present.
I guess you use on of those menus which invokes the Push Wizard. That one allows to push to arbitrary locations, independent of the current repository. Instead of doing this all the time, please configure an upstream configuration, so you can push to upstream without any location selection.
If you really work with multiple remotes and want to push to more than one repository regularly, then you should have each of those remotes configured with its specific push URL and specification. That way you can push to different remotes by just selection the push context menu on a remote (without any additional selection).