Problems SourceTree listing files in local repository as deleted - macos

We are two developers working on a large project which involves 30 small satelllite web sites from two differente stations. We have been experiencing problems with SourceTree in the sense that sometimes in the OSX station the area "Work Copy Changes" lists many files as deleted and reques
A. Main issue:
Sometimes, before committing or pushing any changes on the repository, on the MAC station SourceTree shows on the working changes area that many files have been deleted. But when we check if the files still exist on the project folder of the MAC, they are still there.
We cannot proceed to pull or pushing any more changes until we go file by file ignoring the changes for each file or we make another commit confirming the deletion of the files.
This seems to be happening erratically when one of us pushes changes onto the repository.
Although we don’t know if it may be related to this, another issue that has been happening as well is that the folders requested to be ignored on the gitignore file are not ignored.
B. Configuration
A Samsung laptop running on Windows 7 and a MAC with OSX
For managing (pushing, pulling, committing) contents on the repository, we are using the latest versions of SourceTree (1.5.2 for Windows and 1.9 for OSX)
We are using the same software for development (PhpStorm)
We are using one master repository and branch for managing all the changes on the satellites
The configuration of the GIT config files is below:
Windows station:
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
[remote "origin"]
url = dlaggit#dev.dreamit.de:lotto-satellites
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
OSX station:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = false
[remote "origin"]
url = dlaggit#dev.dreamit.de:lotto-satellites
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
C. What we have tried so far
Discarding the changes on the files. The problem has arisen again weeks later with different files
Reinstalling SourceTree and making the changes below (highlighted) to the git config file on the OSX machine:
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = dlaggit#dev.dreamit.de:lotto-satellites
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
After trying the solution above, some of the files on the working copy changes area no longer appear as deleted but as modified (even though they had not been modified by us), some of them appear recently added and some remain as deleted. When we check the files in the local folder, the files are still there.
Thanks for any help you can provide.

Related

Managing personal and organisation GitHub accounts on the same machine(HTTPS)

So i have a mac given to me by organistaion for company work. My mac os verison is macOS Monterey version 12.6
Now i have one github account setup here for my company (2FA enabled and using HTTPS with Personal access token)
git version 2.37.0 (Apple Git-136)
Adding .git/config file output here (local file inside repo path).
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/<<company_name>>/<<repo_name>>.git
fetch = +refs/heads/*:refs/remotes/origin/*`
Adding global config file output (~/.gitconfig)
[credential]
helper = osxkeychain
[url "https://company_username#github.com"]
and inside keychain there are two enteries for github.com
Internet password
application password
Both having my personal access token for the company id.
This all works fine as PAT is saved in keychain.
Now i have created a new github account under my name (for personal projects) and following is the local .git/config file output there.
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[user]
name = <<personal_username>>
email = <<personal_email_id>>
[remote "origin"]
url = https://<<PAT>>#github.com/<<personal_username>>/<<repo_name>>.git
fetch = +refs/heads/*:refs/remotes/origin/*
[credential]
helper =
i have added PAT here so that it does not copies the one from keychain (as i tried different solutions online)
However, when i try to clone or push in this repo it gives error.
remote: Repository not found.
fatal: repository 'https://github.com/<<personal_user>>/<<repo>>.git/' not found
what i understand is it is taking PAT from keychain and that one is for my company's PAT so giving this error. However i might be wrong.
Adding output for my .netrc
machine github.com login <<company_username>> password <<company_PAT>>
I am able to think of two ways to do this
enable keychain for only company's repo and not for personal repo so that i can add PAT personal each time
Add different PAT for different account in keychain
However i am not able to come up with any solution after trying everything online.
Again, i am using HTTPS
(most of solution online are .SSH)
Thank you in advance.
https://<<PAT>>#github.com: you do not put the token when you work with credential helper.
You put your GitHub user account, the one you need to access that repository.
And you record in the credential helper the right PAT for that user.
I would recommend installing the Microsoft cross-platform GCM (Git Credential Manager), which will update osxkeychain.
Then record your personal user account and associated PAT:
printf "host=github.com\nprotocol=https\nusername=you\npassword=PAT" | git credential-manager store
# replace 'you' and 'PAT' with your own GitHub account and token
Using https://you#github.com/... (instead of https://company_username#github.com)will force Git to extract the right token from the credential helper.

Can I get the upstream remote branch by ruby-git

I'm using ruby-git to operate my Git repo. I can get the local branch that checkout from remote branch, how can I get it upstream remote branch? This's the code:
require 'Git'
repo = Git.open("xxxpath.git")
localbranch = repo.branches["localbranchnamexxx"]
The same way you would do it in normal git
remote_branch = repo.branches["origin/localbranchnamexxx"]
Counter-intuitively (to me, at least), the branch tracking information is stored in the git config, not in any branch or ref structures.
require 'git'
repo = Git.open("xxxpath.git")
localbranch = repo.current_branch
upstream_remote = repo.config["branch.#{localbranch}.remote"]
upstream_ref = repo.config["branch.#{localbranch}.merge"]
upstream_branch = upstream_ref.split('/').last
upstream = "#{upstream_remote}/#{upstream_branch}"

TortoiseGit: Start Commit Hook not executed if "Run for this repository" is checked

I just started using Git with the TortoiseGit 2.8.0.0 client on Windows 10 and was trying to set up some client-side hooks. I would like to set them up in a way so that they are automatically set when I or my colleagues clone the repo so I checked "Run for this repository".
I noticed that the Start-commit Hook isn't being executed in that case. Pre-commit and Post-commit seem to work as expected.
If I provide the working tree path and don't check "Run for this repository" all scripts also run as expected.
For testing I just set the same script for all 3 hooks to see if they are working.
My .tgitconfig looks like this:
[hook "startcommit"]
cmdline = %root%\\ARM\\start_commit.bat
wait = true
show = false
[hook "postcommit"]
cmdline = %root%\\ARM\\start_commit.bat
wait = true
show = false
[hook "precommit"]
cmdline = %root%\\ARM\\start_commit.bat
wait = true
show = false
Can anyone explain this behaviour and how to fix it? am I missing something here?
That's a reproducible bug which will be fixed with the next (preview) release (version >= 2.8.4 are fixed).
There is no workaround, but to define it with a repository path, too.

Rugged - fetch, pull rebase possible?

Using rugged how do you perform the following operations: fetch, pull and rebase?
I am using the development branch and after reviewing its documentation found here as a guide to the Remote class.
EDIT: Since git pull is just a shorthand for git fetch and git merge FETCH_HEAD the better question is how to perform git fetch, git merge and git rebase.
git fetch:
remote = Rugged::Remote.lookup(repo, "origin")
remote.connect(:fetch) do |r|
r.download
r.update_tips!
end
git merge:
merge_index = repo.merge_commits(
Rugged::Branches.lookup(repo, "master").tip,
Rugged::Branches.lookup(repo, "origin/master").tip
)
raise "Conflict detected!" if merge_index.conflicts?
merge_commit = Rugged::Commit.create(repo, {
parents: [
Rugged::Branches.lookup(repo, "master").tip,
Rugged::Branches.lookup(repo, "origin/master").tip
],
tree: merge_index.write_tree(repo),
message: 'Merged `origin/master` into `master`',
author: { name: "User", email: "example#test.com" },
committer: { name: "User", email: "example#test.com" },
update_ref: 'master'
})
git rebase:
Rebasing was not implemented yet in libgit2, and thus is not available in Rugged.
In general, your use case sounds very high level, while the rugged API is currently a bit more focused on low-level git repository access and modification. Eventually, we'll also have many higher-level helpers (like a more simple/correct pull) in the future, but we're not there yet.
The answer above seems to be outdated. The syntax has changed. I need to implement a pull action which i am trying to do by a fetch and then a merge and commit. For fetching i use the fetch method like this
repo.fetch('origin', [repo.head.name], credentials: credits)
And it seems to actually get something since the returned hash is full with information about what has been fetched. However, it is not written to disk. I would expect the branch to be behind several commits when i do git status in the command line but it is not. If i fetch a second time with the same command above then nothing is fetched. This is probably because it has already been fetched the first time but then i dont see where the fetch is.
Now if i go ahead and do the fetch manually in the command line and then try to merge the local copy of the remote branch and the local branch (local changes are already committed) using the following code
ref_name = repo.head.name # refs/heads/branchname
branch_name = ref_name.sub(/^refs\/heads\//, '') # branchname
remote_name = "#{remote}/#{branch_name}" # origin/branchname
remote_ref = "refs/heads/#{remote_name}" # refs/heads/origin/branchname
local_branch = repository.branches[branch_name]
remote_branch = repository.branches[remote_name]
index = repo.merge_commits(local_branch.target, remote_branch.target)
options = {
author: { time: Time.now }.merge(author),
committer: { time: Time.now }.merge(committer),
message: 'merged',
parents: [
local_branch.target,
remote_branch.target
],
tree: index.write_tree(repository),
update_ref: 'HEAD'
}
Rugged::Commit.create repo, options
It creates the commit as expected. The commit is also written to disk and is visible in the fistory. But for some reason the branch has now uncommitted changes. The local file contents have not changed. I would expect them to have the contents of the fetched commit.
Can anyone please provide a working example for a fetch, merge, commit? The version of rugged at time of writing this is 0.22.0b3
Update 1
This will bring my working tree to the wanted state
repo.checkout ref_name, strategy: :force
Update2
I found out how to fetch and save the state to disk
r = repo.remotes[remote]
r.fetch(credentials: git_credentials)
r.save

git, strange upstream entry which i cant get rid of

if i do
git remote -v
i get
origin https://..../foo.git (fetch)
origin https://..../foo.git (push)
upstream
this last upstream line there prevents me from adding a real upstream which i wanna merge from.
my config file looks like this:
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
[remote "origin"]
url = https://..../foo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
when i do
git fetch upstream
i get this error:
fatal: 'upstream' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
how can i get rid of that upstream?
Git has several scopes where config is set : system ($(prefix)/etc/gitconfig), global (~/.gitconfig) and local (.git/config of the current repository).
Since there is nothing about upstream in your local scope, you have to check the system and global scopes. It could simply be a write access permission to associated files.

Resources