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

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!

Related

Enabling github pre commit hooks in origin for all collaborators

first: We use a github repository in the team for some projects.
I'm using scripts defined in the pre-commit hook directory, locally (works perfect for my commits).
What I need is for every user (collaborator) to use the hooks without using symlinks or asking them to put them on their home folders.
Is there a way to set them up so the users can't commit if the scripts don't exit 0?.
Thanks.
As Henrik alluded to, in the Enterprise version, there is such a thing as the pre-receive hook. It runs server side and so you would not need to install it on each collaborator's local machine. But you are using github.com actual, and they don't allow pre receive hooks , nor do I expect they plan to; allowing indivduals to run scripts on their server isn't likely in their business plan. So that likely won't help you unless you are in a position to go to the enterprise product
There are some remedies you do have, however, but it won't be equivalent. You can , for example, set a protected branch . You could thereby make it only you can check into that branch, and you of course would be using the local hook, every one else would be using a pull request.
Additionally, you could look into LGTM (Looks Good To Me) or similar automated pull request approval system. I don't believe the official server is up but the source code is there and it could be run by someone else. LGTM allows you to set a number of different conditions that would be closer to an equivalent to your pre-op hook.
Setting up such a system might well be more effort than it is worth to you, understandable; but it is do-able.
The main problem with using pre-commit hooks that come with git is that they are local to your repos and don't get pushed to github.com. I believe under the hood, those hooks aren't even transferred up to the repo on github, and that the pre-commit hook directory itself is not available like it is on the local copy of a git repo.
(I would say more on that architecture of the pre-commit hook dir except A. I am not sure if it is covered by NDA and B. I only saw the way it was on the Enterprise product, not github actual, and C. I don't know if the structure is still exactly the same)

Mercurial. Delete a branch pushed to repository

I pushed a branch to the repository that is never going to be used again. How can I delete it ?
You cannot delete anything on a remote repository. History editing actions do need local acces (e.g. also via web interface like availabe on bitbucket).
If you have local access to the repository, then you can strip the changesets which you do not want anymore. Mind, that it's altering history, thus make a backup before. Also mind, that anyone who pulled those changes and does not strip them locally, too, will bring them back, if that person pushes to that repo.
EDIT to add:
That said, if you make use of phases, have a non-publishing repository as server, and the changes you pushed are of draft phase, then it is possible to simply strip the changes without local access. This is especially useful, if you use the evolve extension.

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.)

Libgit2sharp how to do a mirror 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.

Auto commit and auto push changes in local repo to git

I have a local development system where I have a Ubuntu-Server VM and I use eclipse in windows host. I develop in eclipse using Remote System Explorer & SSH. I want that whenever I save a file or do some changes in ubuntu-server's /var/www/site-folder it automatically commits and pushes the changes in my git repo. I did try the google but it wasn't much of a help. Any help is appreciated guys. Really wanna improve my workflow.
This sounds like something you'll have to script. If you save as much as I do (a lot), then you'll end up with a lot of commits. Unless you're careful about when you save, you'll probably end up with a messy history, unless you squash things later.
Are you sure that you want to commit and push automatically every time you save? It also matters whether or not you're pushing to your own private branch or repo.
Actually I think there are use cases where this /is/ a good idea. If you work on two different machines (even not simultaneously), for instance, you cannot share the Eclipse workspace. One simple way to overcome this is to put a bare git repository on a cloud server (dropbox, copy, one drive, etc) and push all work, completed or otherwise, to that everytime you close eclipse.
Will the repo be messy? Sure, but that's not the point.
I could find no easy hooks within Eclipse itself to automate this so I simply put an invocation of Eclipse in a script and finished off with:
git commit -a -m "WIP commit"
git push origin
You just have to watch out for newly-created files and remember to add those before you exit.