file mask to exclude *.m.swp files in git - gitignore

When I run git status, *.m.swp files are showing up in the "untracked list" because I currently have these files open in MacVim (The originals are MATLAB files with *.m file extensions).
I have tried adding *.m.swp, and various permutations of this, to my .gitignore file so that the files are ignored, but nothing seems to work for me.
See an example of git status output below:
git status
# On branch mybranch1
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: ../dir1/file1.m
# new file: file2.m
# new file: file3.m
# modified: file4.m
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# ../../dir2/.file5.m.swp
# ../dir1/.file6.m.swp
# ../dir1/.file1.m.swp
# ../dir1/.file7.m.swp
# ../dir1/.file8.swp
# .file9.m.swp
# .file4.m.swp
How can I get git to ignore these? Thanks in advance for any help!

.*.m.swp
should work: I have tested it in my msysgit1.7.4 environment.
So: not "*..." but ".*...".
Don't forget to add your modified .gitignore to the index before doing a new git status.

.*\\.m\\.swp
do this instead, since unescaped .'s match anything

Related

How to patch remote source code locally in yocto project?

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)

Buildroot Package Makefile: How to fetch the most recent commit from git?

I am working on adding my own module to the build of buildroot using $BR2_External. The make file of my package is as follows,
##############################################################
#
# GPIO
#
##############################################################
GPIO_VERSION = '2851a05c9b613c1736f79faa185a11118b229852'
GPIO_SITE = '<URL of git repo>'
GPIO_SITE_METHOD = git
GPIO_GIT_SUBMODULES = YES
GPIO_MODULE_SUBDIRS = GPIO_driver/
# GPIO_MODULE_SUBDIRS += GPIO_driver/
# define LDD_BUILD_CMDS
# $(MAKE) $(TARGET_CONFIGURE_OPTS) -C $(#D)/misc-modules
# $(MAKE) $(TARGET_CONFIGURE_OPTS) -C $(#D)/scull
# endef
#
# # TODO add your writer, finder and finder-test utilities/scripts to the installation steps below
define GPIO_INSTALL_TARGET_CMDS
#module
# $(INSTALL) -m 0755 $(#D)/01_simple_LKM/* $(TARGET_DIR)/usr/bin
$(INSTALL) -m 0755 $(#D)/GPIO_driver/* $(TARGET_DIR)/usr/bin
endef
$(eval $(kernel-module))
$(eval $(generic-package))
This make file always pulls only a specific commit (mentioned in GPIO_VERSION variable) from gitHub. This is getting a little frustrating as, everytime I push new code to git I have to update the make file with the new commit number as well. So, is there any way to write the make file such that the most recent commit is pulled.

Ignoring a local file is deleting the depot file

I am using smartgit with github.
I have a config.json file on my remote github depot, with hidden passwords, at the root of the app .
I need to keep a different config.json file on my local depot, with real passwords.
As long as I try to ignore config.json locally, sometimes , it is still recorded as 'modified'
Some others times, when it finally gets ignored, by right clicking/ignore, It says 1'staged' , config.json finally gets deleted from Github when pushing the commit, I don't understand why:
THis is my .gitignore file :
.DS_Store
/config.json
config.json
node_modules
/uploads
/node_module
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
My config.json file , with blank that I need to leave as this on Github, because Heroku needs it :
{
"localhost_db": "mongodb://localhost:27017/",
"mongoDb_atlas_db": "mongodb+srv://jose:x#cluster0-6kmcn.azure.mongodb.net/vue-starter-webpack?retryWrites=true&w=majority",
"dev": false,
"db_name": "vue-starter-webpack",
"ftp_config": {
"host": "ftpupload.net",
"user": "epiz_26763901",
"password": "x",
"secure": false
},
"node_file_path": "./tmp/files/",
"cloudinary_token": {
"cloud_name": "ddq5asuy2",
"api_key": "354237299578646",
"api_secret": "x"
},
"logs_path": "tmp/logs/logs.txt"
}
Is there any workaround ? I have tried plenty of things already. What does "staged" means ? How can I keep a different version of file on github and locally ?
EDIT : I am trying out this command, it seems to work ! :
git update-index --assume-unchanged config/database.yml
Ignore modified (but not committed) files in git?
I have a config.json file on my remote GitHub depot, with hidden passwords, at the root of the app.
That... is not a good practice. If that file (config.json) contains any sensitive information, it should not be added/committed, but explicitely ignored.
What you can commit is config.json.tpl, a template file (which is essentially what your config.json is right now)
From there, you could generate the right config.json file locally, and automatically on git clone/git checkout.
The generation script will:
search the right passwords from an external secure referential (like a vault)
replace the placeholder value in config.json.tpl to generate the right config.json
For that, do register (in a .gitattributes declaration) a content filter driver.
(image from "Customizing Git - Git Attributes", from "Pro Git book")
The smudge script will generate (automatically, on git checkout or git switch) the actual config.json file as mentioned above.
Again, the generated actual config.json file remains ignored (by the .gitignore).
See a complete example at "git smudge/clean filter between branches".

Apply and commit a patch from bitbake recipe

I am observing that the yocto build system is just applying my patch instead of applying and committing the patch on the cloned git repo.
Original bitbake (u-boot-ti-staging_2018.01.bb) file.
require u-boot-ti.inc
PR = "r19"
BRANCH = "ti-u-boot-2018.01"
SRCREV = "8b2f1df4b55bc0797399a21d42ac191d44f99227"
Modified bitbake file, added SRC_URI to the file.
require u-boot-ti.inc
PR = "r19"
BRANCH = "ti-u-boot-2018.01"
SRCREV = "8b2f1df4b55bc0797399a21d42ac191d44f99227"
SRC_URI += "file://0001-Stopping-DHCP-server-giving-new-serverip.patch \
"
I have added a patch file under files directory. The content of the patch (0001-Stopping-DHCP-server-giving-new-serverip.patch) file is as follows.
From cf97b6053f00afd496d01a892599cd8f4b254087 Mon Sep 17 00:00:00 2001
From: Sunny Shukla <sunny.shukla#xyz.com>
Date: Wed, 19 Sep 2018 18:23:49 +0530
Subject: [PATCH] Stopping DHCP server giving new serverip
Added CONFIG_BOOTP_SERVERIP in the config file, this
stops the DHCP server gives new "serverip" address and
overrides the current one.
---
include/configs/am335x_evm.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/include/configs/am335x_evm.h b/include/configs/am335x_evm.h
index 01f0277..4b3047d 100644
--- a/include/configs/am335x_evm.h
+++ b/include/configs/am335x_evm.h
## -18,6 +18,8 ##
#include <configs/ti_am335x_common.h>
+#define CONFIG_BOOTP_SERVERIP
+
#ifndef CONFIG_SPL_BUILD
# define CONFIG_TIMESTAMP
#endif
--
2.7.4
The patch is applying like someone is executing a "git apply 0001-Stopping-DHCP-server-giving-new-serverip.patch" command on top of the cloned git repo as show below. But rather I want that the patch must be applied like someone is executing a "git am 0001-Stopping-DHCP-server-giving-new-serverip.patch" command on top of the cloned git repo.
git status
On branch ti-u-boot-2018.01
Your branch is behind 'origin/ti-u-boot-2018.01' by 23 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: include/configs/am335x_evm.h
no changes added to commit (use "git add" and/or "git commit -a")
I want this patch to be applied and committed on top of the cloned git repo. How to achieve that under a bitbake file?
Yocto by default uses quilt when no patch tool is specified. You can specify
PATCHTOOL = "git"
in your recipe, so that Yocto automatically applies it using "git am".
See here for more details.
NOTE: This functionality will start adding an extra line to the patch's description like "%%original patch: 0001-Stopping-DHCP-server-giving-new-serverip.patch" while applying the patch. To get rid of it, comment the below line under "oe-core/meta/lib/oe/patch.py" file.
https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/lib/oe/patch.py#n519

Referencing current branch in github readme.md

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.