I can commit loads of changes, but nothing gets to github.
Its only when I manually click the PUSH function from the menu that it pushes to github.
How can I get it to do this automatically when I commit?
These are my VS GIT settings:
// Whether git is enabled
"git.enabled": true,
// Path to the git executable
"git.path": null,
// Whether auto refreshing is enabled
"git.autorefresh": true,
// Whether auto fetching is enabled
"git.autofetch": true,
// Confirm before synchronizing git repositories
"git.confirmSync": true,
// Controls the git badge counter. `all` counts all changes. `tracked` counts only the tracked changes. `off` turns it off.
"git.countBadge": "all",
// Controls what type of branches are listed when running `Checkout to...`. `all` shows all refs, `local` shows only the local branchs, `tags` shows only tags and `remote` shows only remote branches.
"git.checkoutType": "all",
// Ignores the legacy Git warning
"git.ignoreLegacyWarning": false,
// Ignores the warning when there are too many changes in a repository
"git.ignoreLimitWarning": false,
// The default location where to clone a git repository
"git.defaultCloneDirectory": null,
// Commit all changes when there are not staged changes.
"git.enableSmartCommit": false,
According to this issue on GitHub, this feature does not exist and is not planned to be added.
They suggest using Git hooks to achieve this behavior.
Something like this:
#!/usr/bin/env bash
branch_name=`git symbolic-ref --short HEAD`
retcode=$?
# Only push if branch_name was found (my be empty if in detached head state)
if [ $retcode = 0 ] ; then
#Only push if branch_name is master
if [[ $branch_name = "master" ]] ; then
echo
echo "**** Pushing current branch $branch_name to origin ****"
echo
git push origin $branch_name;
fi
fi
You can check this answer for more details and options.
Related
Sometimes, We meet a situation that remote source code fetched by a recipe need to be modified so that suit a specific machine.
How do we create a patch for remote source code locally? After that everytime we build the recipe (even clean it all) we can patch the remote source code automatically.
For example, I have a special machine with architecture A which is not common, so the remote source code need to be modified so that support architecture A.
Suppose there was a file called utils.h (which is code that we fetched by example.bb from remote git repository)
#if defined(__x86_64__) || \
defined(__mips__) || \
defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) \
#define SOME_FUNCTIONALITY 1
Apparently I need to add archtecture A support in the file.
#if defined(__x86_64__) || \
defined(__mips__) || \
defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) || \
defined(__A__) \
#define SOME_FUNCTIONALITY 1
But if we just modified like that, next time we execute
bitbake -c cleanall example
bitbake example
then we get a unchanged copies again(which means we have to modify it again).
How do we create a Add-architecture-A-support.patch locally so that we can patch the remote source code automatically?
This is a simple one from answers.
(Note: If there was no git in the source code directory, before modifying the source code, you need to create a git repository and commit all in the top directory of the source code.)
git init # create a git repository
git add .
git commit -m "First commit" # first commit
After change the utils.h as above, we can check the git status. It usually looks like that.
$ git status
HEAD detached from 87b933c420
Changes not staged for commit:
(use "git add <file>..." to update what will be comitted)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: ../../utils.h
...
no changes added to commit (use "git add" and/or "git commit -a")
Then we add and commit the change locally (usually we don't have the permission to push to upper stream).
$ git add utils.h
$ git commit -m "Patch test"
After that we can use git to create a patch for the recent commit.
$ git show >Add-architecture-A-support.patch
It will creat a patch in the current directory with contents looks like that
commit a79e523...
Author: 杨...
Date: ...
Patch test
diff --git a/somedir/utils.h b/somedir/utils.h
index 20bfd36c84..
--- a/somedir/utils.h
+++ b/somedir/utils.h
...
+ defined(__A__) \
...
Then we can move the patch to the local layer where the recipe stayed.
recipe-example
|-- example
| |-- Add-architecture-A-support.patch
|-- example.bb
And add the patch in example.bb with this.
SRC_URI += "\
file://Add-architecture-A-support.patch \
"
Work finished. (Also, if want to undo the local commit after creating the patch, you can use git reset HEAD^ utils.h. emmm, I think so, maybe there are some faults, just google it)
In one git repository (workspace), I want every save committed ASAP. What is the easiest way to achieve that with VSCode?
So, when I press CTRL + S, it gets pushed upstream.
This can be done with plugin Run on Save
Here is the example that auto commits and pushes upstream any changes in the directory mydir:
"emeraldwalk.runonsave": {
"commands": [
{
"match": "\\\\mydir\\\\",
"isAsync": false,
"cmd": "cd ${fileDirname}",
},
{
"match": "\\\\mydir\\\\",
"isAsync": false,
"cmd": "git add -A",
},
{
"match": "\\\\mydir\\\\",
"isAsync": false,
"cmd": "git commit -a -m \"vscode autosave\"",
},
{
"match": "\\\\mydir\\\\",
"isAsync": false,
"cmd": "git push",
}
]
}
One way to achieve that is via terminal on VSCode. Change to the topmost directory containing the .git file and run the following commands:
git status
This shall show you the uncommitted changes. Then run the following for the new added changes (except for the remove changes)
git add <fileName>
This shall add all the added contents to index.
Run below for the remove changes.
git rm <filename>
Then, git commit -m <commit msg> to commit the changes.
I've scoured several different posts but there doesn't appear to be any that match with this exact issue of an "apparent" branch renaming occurring but nothing seeming to line up.
Essentially, I've been trying to delete a remote branch off of an enterprise git version but I've been getting rejected and I was wondering if there was any additional steps I can try out?
here is the following CLI information:
| => git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/releases/v1.7.2_log4j2
(base)
| ~/Documents/<repo> # (user)
| => git push origin -d releases/v1.7.2_log4j2
To https://github.<company>.com/<org>/<repo>.git
! [remote rejected] releases/v1.7.2_log4j2 (branch releases/v1.7.2_log4j2 is being renamed)
error: failed to push some refs to 'https://github.<company>.com/<org>/<repo>.git'
My git version: 2.24.3 (Apple Git-128).
EDIT: there are no branch protection rules that apply to this branch and I have tried the command in the suggestions of git push -d origin releases<1.7.2_log4j2 with the same result
This looks like a github issue. There is a github-community thread where someone got the exact same message and it turned out to be a flag that was set within the github system that marked the branch as being renamed at the moment. They had to ask the github-support to clear that flag and then were able to delete the branch.
You seem to have your parameters backwards. Try
git push -d origin releases/v1.7.2_log4j2
I am developing a library on github that has travis checks attached to it. I'd like to have a WIP pull request open to discuss ideas easily. There is a lot of tests set up for the project on travis, so I'd like to not trigger the tests every time I push a commit (to prevent server for being overloaded), as the code is not expected to pass anyway.
Is there a way I could do this on github without having access to travis configuration?
To skip builds on a per-commit basis you can add [ci skip] to the commit message, as described in the Docs, for example:
Before: Add blerb.
After:
Add blerb
[ci skip]
To skip all non-PR builds, you can early-exit if the TRAVIS_PULL_REQUEST environnment variable is set to "false" fron your .travis.yml:
before_install: # Earliest build step
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo "Not a PR, skipping" && exit; fi
My approach is to use an alias that I defined that appends the [ci skip] to each commit message of the current branch.
wip = "!f() { git filter-branch -f --msg-filter 'sed -e "\"s/$/ \\[ci skip\\]/g\""' ${1-master}..HEAD ; }; f"
unwip = "!f() { git filter-branch -f --msg-filter 'sed -e "\"s/ \\[ci skip\\]//g\""' ${1-master}..HEAD ; }; f"
wpush = "!f() { git wip $1 && git fpush && git unwip $1 ; }; f"
So basically what I do is simply git wpush.
In my github repo's readme.md file I have a Travis-CI badge. I use the following link:
https://travis-ci.org/joegattnet/joegattnet_v3.png?branch=staging
The obvious problem is that the branch is hardcoded. Is it possible to use some sort of variable so that the branch is the one currently being viewed?
Not that I know of.
GitHub support confirms (through OP Joe Gatt 's comment)
The only way to do this would be to pass the link through my own service which would use the github's http referrer header to determine which branch is being referenced and then fetch the appropriate image from Travis CI
I would rather make one Travis-CI badge per branch, for the reader to choose or consider the appropriate when seeing the README.md.
Update 2016 (3 years later): while nothing has changed on the GitHub side, fedorqui reports in the workaround mentioned in "Get Travis Shield on Github to Reflect Selected Branch Status" by Andrie.
Simply display all the branches and their respective TravisCI badges.
If you have only two or three branches, that could be enough.
I worked around this issue with a git pre-commit hook that re-writes the Travis line in the README.md with the current branch. An example of usage and pre-commit (Python) code (for the question as asked) are below.
Usage
dandye$ git checkout -b feature123 origin/master
Branch feature123 set up to track remote branch master from origin.
Switched to a new branch 'feature123'
dandye$ echo "* Feature123" >> README.md
dandye$ git add README.md
dandye$ git commit -m "Added Feature123"
Starting pre-commit hook...
Replacing:
[![Build Status](https://travis-ci.org/joegattnet/joegattnet_v3.png?branch=master)][travis]
with:
[![Build Status](https://travis-ci.org/joegattnet/joegattnet_v3.png?branch=feature123)][travis]
pre-commit hook complete.
[feature123 54897ee] Added Feature123
1 file changed, 2 insertions(+), 1 deletion(-)
dandye$ cat README.md |grep "Build Status"
[![Build Status](https://travis-ci.org/joegattnet/joegattnet_v3.png?branch=feature123)][travis]
dandye$
Python code for the pre-commit code
dandye$ cat .git/hooks/pre-commit
#!/usr/bin/python
"""
Referencing current branch in github readme.md[1]
This pre-commit hook[2] updates the README.md file's
Travis badge with the current branch. Gist at[4].
[1] http://stackoverflow.com/questions/18673694/referencing-current-branch-in-github-readme-md
[2] http://www.git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
[3] https://docs.travis-ci.com/user/status-images/
[4] https://gist.github.com/dandye/dfe0870a6a1151c89ed9
"""
import subprocess
# Hard-Coded for your repo (ToDo: get from remote?)
GITHUB_USER="joegattnet"
REPO="joegattnet_v3"
print "Starting pre-commit hook..."
BRANCH=subprocess.check_output(["git",
"rev-parse",
"--abbrev-ref",
"HEAD"]).strip()
# String with hard-coded values
# See Embedding Status Images[3] for alternate formats (private repos, svg, etc)
# [![Build Status](https://travis-ci.org/
# joegattnet/joegattnet_v3.png?
# branch=staging)][travis]
# Output String with Variable substitution
travis="[![Build Status](https://travis-ci.org/" \
"{GITHUB_USER}/{REPO}.png?" \
"branch={BRANCH})][travis]\n".format(BRANCH=BRANCH,
GITHUB_USER=GITHUB_USER,
REPO=REPO)
sentinel_str="[![Build Status]"
readmelines=open("README.md").readlines()
with open("README.md", "w") as fh:
for aline in readmelines:
if sentinel_str in aline and travis != aline:
print "Replacing:\n\t{aline}\nwith:\n\t{travis}".format(
aline=aline,
travis=travis)
fh.write(travis)
else:
fh.write(aline)
subprocess.check_output(["git", "add", "README.md" ])
print "pre-commit hook complete."
I updated the work of Dan Dye so it's now able to change any git variable into a readme. It also works now with python 3. For example, handling badges by branch for Github actions:
[![Integration Tests](https://github.com/{{ repository.name }}/actions/workflows/integration-tests.yaml/badge.svg?branch={{ current.branch }})](https://github.com/{{ repository.name }}/actions/workflows/integration-tests.yaml?query=branch%3A{{ current.branch }})
And in your pre-commit file add:
.githooks/replace_by_git_vars.py readme.md README.md -v
-v displays the available variables and more
https://gist.github.com/jclaveau/af2271b9fdf05f7f1983f492af5592f8
Thanks a lot for the solution and inspiration!
The best solution for me was to create a server where I send a query with username and repo's name and get a svg image with the build status for all branches.