how to find out which git-branch a dependency in go.mod belongs to by command-line? - go

I want to write a shell program to check whether all go module dependencies in my project are on newest master version in their repositories. In particular, I want to know which branch each module is on. There is a file "go.mod" containing each dependency listed as {module}-{commit time}-{commit ID}. How can I get their git-branch name from SHA-1(commit id) or other message by shell program.
I have tried go list -m -u all, only showing the newest edition if the dependency is not up-to-date. etc. git.xxx.com/project v0.0.0-20191119034146-e894bf51bdcd [v0.0.0-20200609070643-fd412b12b811]. Without cloning the repos, can go module tools resolve this quetion?

I couldn't figure out how to find which branch the current dependency belongs to using only go tools. But there is a way to find which branch the commit is on using git.
git clone <repo-url> && cd <repo> && git branch -a --contains <commit>
Reference: Finding what branch a Git commit came from

Related

Issues with 'go build' on forked repository

I build a binary file for a GitHub repo (go code), which works fine. no issues.
I forked that repo, and modified a single line in the HTML file that has nothing to do with GO code, built the binary file for the new forked repo but the binary it generates refers to the original repo code, can't understand why.
I even cleaned all the code using go clean -i all command and manually removed all the installed code, binary files from $home/go/bin and the repo directory, but it still refers to the original repo code instead of new forked code.
Based on the solution suggested by Tobias, I performed the following steps:
After that, I executed go build in that repo directory, but the new binary file still refers to the old code. I even removed the old binary file and generated a new one.
That's a common problem in go. The references system in "location based" so it searches for these files in the "correct" path. Idk if go modules fix this issue, but atleast when not using go modules you'll have to work around it.
You can solve it by
Solution 1
Download the original repository you forked by:
go get http://github.com/awesome-org/tool
Add your fork as remote
git remote add awesome-you-fork http://github.com/awesome-you/tool
You'll have to make changes in the folder of the original downloaded repo and Push and Pull to/from your fork.
git pull --rebase awesome-you-fork
git push awesome-you-fork
Solution 2
Work around go get:
You create the path the original repo would have, but clone your own fork into it. That way you can push & pull to your fork. That may be the better solution
cd $GOPATH
mkdir -p {src,bin,pkg}
mkdir -p src/github.com/awesome-org/
cd src/github.com/awesome-org/
git clone git#github.com:awesome-you/tool.git # OR: git clone https://github.com/awesome-you/tool.git
cd tool/
go get ./...
These Solutions were found here: http://code.openark.org/blog/development/forking-golang-repositories-on-github-and-managing-the-import-path
The problem with a forked copy of a go packages is when the package is really multiple go packages in one repo, the import statements refer to original base repo, ie: github.com/orig/repo.
This is not an issue for repos with only one go package as it never refers to itself.
But if it has multiple, ie: package github.com/orig/repo/A imports github.com/orig/repo/B
And then you fork it as: github.com/fork/repo
Then when the go compiler sees import "github.com/orig/repo/B" in the source, it goes to download the original version and not your fork.
Fortunately, go modules solves this.
Basically, create a go.mod at the top of your forked repo and add:
module github.com/orig/repo
then, the go compiler will assume that you are "orig/repo" regardless of where you actually are checked out from.
so, when orig/repo/A imports orig/repo/B, it will look locally.
If there are other imports you need to override that are outside the main forked repo, you can also force dependencies to come from another place using replace
SOLVED
At first I thought it was problem with a FORK (which is a common problem experienced with fork of Go language repo's), but it turns out, it was Repo specific problem.
One of the dependent libraries had to be reinstalled for the forked repo to work, which was not mentioned in the Original repo docs.
Finally, this link helped: https://github.com/inconshreveable/ngrok/issues/181#issuecomment-65646229, the problem was not generic but repo specific
I followed the below steps from above link to resolve the dependency on go-bindata
go get github.com/jteeuwen/go-bindata
cd $GOPATH/src/github.com/jteeuwen/go-bindata/go-bindata
go build

how to update the vendor folder for https://github.com/hashicorp/terraform.git for terraform

Hi i am following steps given for hashicorp/terraform and performed below activity
# Get latest master branch's dependencies staged in local $GOPATH
git checkout master
git pull
godep restore -v
# Make your way to the dependency in question and checkout the target ref
pushd $GOPATH/src/github.com/some/dependency
git checkout [latest]
# Head back to Terraform on a feature branch and update the dependncy to the
# version currently in your $GOPATH
popd
git checkout my-feature-branch
godep update github.com/...
after this i can see my Godep.json file has been updated however i dont see changes in the vendor folder . it still points to old. Well i am looking emr support from vendor for that i am updating go-aws-sdk which is available with the latest go-aws-sdk. when i called go update github.com/... it has modified the godep.json but not vendor folder .
Could somebody please let me know the reason. Thanks
You have to do a godep restore -v again. update only updates the dependency in the Godep.json file.

Xcode Bots do not update git submodules to specified commit

My Xcode Bot is using an outdated version of my repo's submodules.
It builds old submodule code despite the submodule being updated to a new version in the commit history of the parent app.
Parent repo uses submodule v1.0.
Parent repo updates submodule to v2.0 and commits subproject commit to github.
The "on commit" Xcode Bot is run for the new commit automatically.
Parent app is uploaded to TestFlight.
TestFlight build contains the correct v2.0 submodule commit (the last commit to parent repo).
However the TestFlight build contains the outdated submodule v1.0 code.
I thought I was going crazy when my bugs were reproducible on the TestFlight build despite being "fixed" in the submodule and local builds.
It turns out Xcode Bots do not properly pull the specified submodule commit.
A simpler solution to this problem which doesn't require the server having credecentials for your git remotes - add this as a pre-integration script for your bot:
#!/bin/sh
# Enumerates each submodule to check out the desired commit.
# Needed because Xcode bots for some reason prefers to check out
# the branch head, which may result in the wrong commit.
cd "$XCS_PRIMARY_REPO_DIR"
git submodule foreach --recursive 'git checkout $sha1'
It recursively enumerates your submodules and checks out the commit expected by the parent repo.
As of Xcode 6, Xcode Bots are not guaranteed to update the repo's submodules to the specified commit.
You will need to manually update the submodules prior to the Xcode Bot's build:
git submodule update --init --recursive
To make this easier I've added updateGitSubmodules to the cavejohnson Xcode Bot scripting tool. Add the following to your Before Integration Run Script phase to update submodules automatically:
Before Integration > Run Script:
#!/bin/bash
PATH=/Library/Frameworks/Python.framework/Versions/3.4/bin:$PATH
cavejohnson updateGitSubmodules
Finally, we've opened an ticket to explore how this behavior can be fixed upstream.

Pull specific revision from master branch?

Im very new to Git and what I want to do with git within xcode is pull an older revision of my master (not commandline). Is this possible? I've looked in repositories under the organizer and i see all my commits there but i cant seem to load in one of them.
You can't go back to an earlier version of a repository from Xcode in Xcode 4. Older versions of Xcode allow you to go back to an earlier version of a repository, but older versions of Xcode lack git support.
I think that if you have cloned/pushed your repo all the stuff you need is on your local drive.
If you want to see how code looks in specific commit, do
git checkout branch_name
or
git checkout 14646bf1a76d08cbda99317c4faa8de0072d6975
where branch_name can be alias for checksum used by git, (like master or origin/master), if you want to list your branch checksums you can do that by
git log
or if you want it in GUI use qgit gitg or my favourite tig, or whatever you'll find to list your commits

Git repo for framework inside local git project in Xcode 4

I have an iOS project in Xcode 4, that is using Git. Now I want to add the MKStoreKit framework to my project. It is already under version control using Git and a public repo. I'd like to include it in my project, and allow my project's git version control to do version control of the currently pulled version of MKStoreKit, while maintaining the ability to clone any updated MKStoreKit code with standard git ease. I see that a git submodule or subtree is probably what I need, but it seems like a real PITA. Is there not a simpler way?
So far any external code I add to my project I clone to a temp directory, then copy the individual files into my project. This feels like a kludgy way to do things.
Check out the submodules section of the Git book. They're not really all that bad.
If you have a git repository, and you want to add another repository as a subdirectory, you can do this:
git submodule add git://github.com/MugunthKumar/MKStoreKit.git mstorekit
Now you have a directory "mstorekit" inside your project that is actually the MStoreKit repository. If someone clones your repository, they'll start with an empty "mstorekit" directory. Running:
git submodule init
git submodule update
Will clone the MStoreKit repository. They'll end up with the HEAD of the MStoreKit repository at the same commit as the one checked in to your repository.
Updating MStoreKit would look like this:
cd mstorekit
git pull origin master
cd ..
git ci -m 'updated mstorekit to latest version'
There are some alternatives out there, including git-subtree, which I saw mentioned recently around here. I have no experience with it (whereas I've been reasonably happy working with submodules).

Resources