Integration to Visual Studio

Hello everybody,

I have a problem with using Git with Visual Studio.

I used it with Visual Studio 2017, I presume in a little fishy way but it worked.

Now that I had to buy a new machine I tried the same script and it does not work on Visual Studio 2019 Community. The system is Windows 10 in both cases, up-to-date for the second case (I bought a new machine to have the place for the updates)

Perhaps somebody can have an advise on this.

Here is my script, I ran a command line window in the folder of the project to launch it.
I have to precise that the “Visual Studio Projects” folder has three sub-folders, one per type of project (WinForm, Web, Console), plus one NewRepo for the “distant” repository.

$b = "\";
$g = """";
$p = (Get-Location).Path;
$d = [System.IO.DirectoryInfo]$p;
$d.Name
$c = "D:\Projets Visual Studio\NewRepo\" + $d.Name
ECHO Git

git init --bare origin
ECHO $p
CD $p
git clone -l . $c
git remote add origin $p
git push --set-upstream origin master
  1. What’s with all the unused variables?
  2. p is a path or folder name not a default branch so git remote add origin $p never should have worked.

Hello,

What’s with all the unused variables?

$b is a backslash, $g a quote mark, you are right that I eventually did not use them, and forgot to remove them.
$p is a string, that contains the path to the current folder.
$d is the corresponding folder.
So, $d.Name corresponds to the end of $p, I could have cut at the last backslash (using $b), but it seemed more simple to do it that way.


In fact, what surprised me was that, as I remember, the script seems to clone the copy to the original instead of the reverse, which, as you say, should never have worked. But, in reality, that worked jolly good. I made the remark on a forum, that inspired no answer.
[I just had a look ; well it seems that remembering is not up-to-date.]

Before that, I tried making the copy in a more intuitive direction, but that never worked.
But anyway that was with another machine, that works no more because of the appetite of Microsoft in disk place for the updates.
Well, now I have got about 800 GB free for system and programs with everything installed, I hope with that I can work a few weeks before the machine being struggled by the updates. Except if Microsoft wants to reinvent the wheel next month ?
Well tell me, I imagine a standard script is proposed somewhere, to be able to clone one’s repository ?
That is not such a rare operation I guess.

Judicious remark.
In the folder, I see an “origin” sub-folder.
So, I modified line 11 to be :

CD $p\origin

Previous version was more flexible with this, you could provide a parent folder of the repository, which seems not to be the case any more.

but when executing (with line 11 corrected) it answers me that I am trying to clone an empty repository.
Uh, Visual Studio automatically created the repository when creating the project, I never had an occasion to verify its contents until I (more validly) tried to clone it.

It seems I now have to make something more explicit to populate the repository.


In fact, the repository was created by Visual Studio, but on the previous machine.
Anything changed in the implementation ?

Hi @gluups,

I am not altogether clear what you are trying to achieve or why.
Can you be a more specific or descriptive than saying “it does not work”… if so there is a better chance of someone in the community helping resolve your problem, or providing a way of achieving what you desire.
For example; What happens when you run the commands outside the script one at a time in sequence in your terminal, what bit does not work, when do you get an error and what is the error?

$c = “D:\Projets Visual Studio\NewRepo” + $d.Name

so general comments are
Is the above syntax deliberately spelt with spelling “Projets” rather than “Projects”?
What folder are you executing this from?
You have a “CD $p” but $p is already set to your current path?
You have init a bare repository in a new subfolder ‘origin’ (.\origin)
but you are trying to clone from “.”?

As you pointed it, the project folder ($p / $d) is no repository. Previous version of Git accepted the parent folder of the repository to be passed as source to clone, but not the current version. So, I modified line 11 to CD $p\origin.
And, as I think I remember, I said at the beginning that NewRepo is the folder for the clones.

So, now, the situation has evolved, the error message is no more the same. The current folder ($p\origin) is a repository, but … an empty repository.

This is why I said it seems I have to do something more explicit to populate the repository (if that can be done after writing code).


Is the above syntax deliberately spelt with spelling “Projets” rather than “Projects”?

I have a french version of Visual Studio, and that folder is named automatically at installation.

In the forum I said “Visual Studio Projects” at a moment for I thought it could be clearer.
But of course the code refers to the real name.


Oh, if I want to give you a copy of the console, I have to get it outside Visual Studio.
Now I have got this :

D:\Projects Visual Studio\Winform\ListIrfanView\ListIrfanView>\scripts1\Repo2.ps1
ListIrfanView
Git
Reinitialized existing Git repository in D:/Projects Visual Studio/Winform/ListIrfanView/ListIrfanView/origin/
D:\Projects Visual Studio\Winform\ListIrfanView\ListIrfanView
Cloning into 'D:\Projets Visual Studio\NewRepo\ListIrfanView'...
warning: You appear to have cloned an empty repository.
done.
error: remote origin already exists.
error: src refspec master does not match any
error: failed to push some refs to 'D:\Projects Visual Studio\Winform\ListIrfanView\ListIrfanView'

Before that it said that the target folder already existed, so I removed it.
Oh, but … “remote origin already exists” has about the same meaning.
Deleting the target folder was not the good way to do it, it seems ?

Is the above syntax deliberately spelt with spelling “Projets” rather than “Projects”?

I did not get it first, but you asked a very good question indeed. I saw that a few weeks ago, and then forgot about it.
On the previous machine, the folder was named “Projets Visual Studio”.
On the current one, the folder is named “Projects Visual Studio”. It was installed by an assembler in the Netherlands, so he used a different installation program. In French there is no c, in English Project is written at the end, so we obtained a strange result.

I corrected this in the new script.
But, before as after the correction, it says me that “remote origin already exists”.
I tried to delete the target folder, but it seems this is not the correct way of doing it.


Oh, what the console shows me is strange, I feel :

D:\Projects Visual Studio\Winform\ListIrfanView\ListIrfanView>\scripts1\Repo2.ps1
ListIrfanView
Git
Reinitialized existing Git repository in D:/Projects Visual Studio/Winform/ListIrfanView/ListIrfanView/origin/
D:\Projects Visual Studio\Winform\ListIrfanView\ListIrfanView
Cloning into 'D:\Projects Visual Studio\NewRepo\ListIrfanView'...
warning: You appear to have cloned an empty repository.
done.
error: remote origin already exists.
error: src refspec master does not match any
error: failed to push some refs to 'D:\Projects Visual Studio\Winform\ListIrfanView\ListIrfanView'

So, I first see “Reinitialized existing repository”, so I have nothing to do manually to populate the repository as I said a moment ago, but then it tells me : “warning: You appear to have cloned an empty repository.”

So, it has reinitialized the repository, but with nothing in it ?

And then I see “remote origin already exists”, so it seems when doing a new attempt I have to clean what I did before, but I am not quite up-to-date about how to do it.


What folder are you executing this from?

Oh yes this is an important question : the script is launched from the (source) project folder. One of the sub-directories is called origin.
Supposing origin is the repository to clone, I modified line 11 to select it :

CD $p\origin

I am refraining from sleeping, and I do not exactly know whether you are still in front of your machine. So, I am going to wait a quarter of an hour, and then if you say nothing it means you are away.
Thank you for the tips already given. It seems a few points still need to be improved.

Oh well, when reading again I realize I mixed up a few things.

Initially the script was supposed to be launched from the project folder, to create an (empty) repository and clone it to the NewRepo directory, before beginning to code.
And, more recently, I copied the project, with its repository, to a new machine.

So, if I execute

git init --bare origin

of course I loose the repository I have in the origin folder.

So, I presume I shall have to create a new project to test that script, and verify that NewRepo contains a save copy of the repository, as was the case on the old machine.

And I presume I have to write another script (perhaps the same with a few modifications) to clone the repository of an existing project that was transferred from the previous machine.
And, in all likelihood, this one will not have to contain

git init --bare origin

as the project already has a repository.

I guess things should be clearer with this, and by the same occasion it is clearer for me too :slight_smile: