How would you write this script, which works perfectly as intended in bash, to work on fish shell? - fish

GIT_COMMITTER_DATE="$(date)" git commit --amend --no-edit --date "$(date)"
This works fine in bash, but I can't get it to run in fish shell. Can someone help me figure out what is the equivalent in fish shell? Thanks.

Turns out there is an equivalent script that doesn't need to use $(date)
git commit --amend --reset-author --no-edit
That does the trick. Thanks!

In fish, use the env external command to alter the environment only for the duration of one command. And of course the command substitution syntax and quoting are different:
env GIT_COMMITTER_DATE=(date) git commit --amend --no-edit --date (date)

Related

How can I get zsh to inherit the complete autocompletion?

I have an little shell script (named "run") which redirects all output of a program to /dev/null:
#!/bin/bash
$# &> /dev/null &
disown +
How can I say zsh that the whole autocompletion shall work for this?
I mean
$ run git com<TAB>
autocomplete to
$ run git commit
I was able to make that work by adding:
compdef _command run
to my .zshrc file.
I've based my answer on this bash question. It was worth giving it a try with compdef - surprisingly it worked.
As I'm still zsh/autocompletion newbie I cannot explain the inner workings and you should probably go through the documentation or other sources to find more on the topic.

Mercurial - how to see the history for a specific line of code

I have a CSS file with thousands of lines of code. I want to see when a specific line/chunk of code was changed, without going back and reviewing each revision that changed this file (that will take a looooong time!)
Is there a way, using either TortoiseHg, Eclipse with a Mercurial plugin, or command-line, to view the history of a specific piece of code?
The correct answer is hg grep (Mercurial grep page).
More deep:
hg grep --all "PATTERN" FILENAME
Sample output:
>hg grep --all "textdomain" functions.php
functions.php:2:-:load_theme_textdomain('fiver', get_template_directory() . '/translation');
functions.php:2:+:load_theme_textdomain('fiver', get_template_directory() . '/languages');
functions.php:1:+:load_theme_textdomain('fiver', get_template_directory() . '/translation');
(in order - filename, revision, action, string in this revision)
You can use:
hg annotate <file>
to find out in which revision line was changed and then use same command with -r <revision> at the end to go backwards through revisions.
I don't think there is an option to view a specific part of a file. But to see the differences of the total file over several revisions you can use hg diff:
hg diff -r firstrevisionnumber:otherrevnumber filename
For example, hg diff -r 0:8 screen.css
Or the command hg log screen.css.
Use hg histgrep --all PATTERN FILENAME (used to be hg grep in the older versions, and that doesn't work anymore)

command expansion: how to convince eshell I'm not trying to execute an elisp expression?

git grep fizzbuzz $(git rev-list --all)
fatal: Invalid object name 'Symbol's function definition is void'.
Of course, the same command in M-x shell works fine.
How do I convince eshell I'm not trying to execute an elisp expression here so I can get the git grep goodness I so clearly seek?
Try:
git grep fizzbuzz ${git rev-list --all}
Works in my emacs if I wrap the $() with backtics, e.g.:
git grep fizzbuzz `$(git rev-list --all)`

How to find out what commit a checked out file came from

When I check out a file with git checkout $commit $filename and I forget $commit but still remember $filename, how do I find out what $commit was?
First a non-git answer. Check your shell command history. Well, if you didn't use a shell with command history then you don't...
The git answer. You generally cannot find THE $commit. Generally the same contents might have been part of many commits and I don't think git keeps a log of what single file you have checked out (it keeps a log of previous values of HEAD)
Here is a brute force script git-find-by-contents. Call it with your $filename as parameter, and it will show you all commits where this file was included. As the name says
it searches by contents. So it will find files with any name, as long as the contents matches.
#! /bin/sh
tmpdir=/tmp/$(basename $0)
mkdir $tmpdir 2>/dev/null
rm $tmpdir/* 2>/dev/null
hash=$(git hash-object $1)
echo "finding $hash"
allrevs=$(git rev-list --all)
# well, nearly all revs, we could still check the log if we have
# dangling commits and we could include the index to be perfect...
for rev in $allrevs
do
git ls-tree --full-tree -r $rev >$tmpdir/$rev
done
cd $tmpdir
grep $hash *
rm -r $tmpdir
I would not be surprised if there is a more elegant way, but this has worked for me a couple of times in similar situations.
EDIT: a more techy version of the same problem appears here: Which commit has this blob?
I don't think you can. Git just loads that version of the file into the index and your working dir. There is no reference keeping track of what version it loaded
If this is something that you do often, you could write up a script that could do it using git diff --cached and march through all the commits that changed that file.
You can use
git log <filename>
to find out which commit you want to checkout
If you're lucky, you could maybe try a non-git way:
history | grep "git checkout.*filename"
Try this (untested ;):
$ for commit in $(git log --format=%h $filename); do
> if diff <(git show $commit:$filename) $filename >/dev/null; then
> echo $commit
> fi
> done
Simple and elegant:
$ git log -S"$(cat /path/to/file)"
Only works if the content is unique, then again that's the same for the hash-comparison answers that came before.
It also displays only the first version that matches, rather than all.
Here are the details of a script I polished up as the answer to a similar question, and here you can see it in action:
(source: adamspiers.org)

How do I get a list of commit comments from CVS since last tagged version?

I have made a bunch of changes to a number of files in a project. Every commit (usually at the file level) was accompanied by a comment of what was changed.
Is there a way to get a list from CVS of these comments on changes since the last tagged version?
Bonus if I can do this via the eclipse CVS plugin.
UPDATE: I'd love to accept an answer here, but unfortunately none of the answers are what I am looking for. Frankly I don' think it is actually possible, which is a pity really as this could be a great way to create a change list between versions (Assuming all commits are made at a sensible granularity and contain meaningful comments).
I think
cvs -q log -SN -rtag1:::tag2
or
cvs -q log -SN -dfromdate<todate
will do what you want. This lists all the versions and comments for all changes made between the two tags or dates, only for files that have changed. In the tag case, the three colons exclude the comments for the first tag. See cvs -H log for more information.
The options for the cvs log command are available here. Specifically, to get all the commits since a specific tag (lets call it VERSION_1_0)
cvs log -rVERSION_1_0:
If your goal is to have a command that works without having to know the name of the last tag I believe you will need to write a script that grabs the log for the current branch, parses through to find the tag, then issues the log command against that tag, but I migrated everything off of CVS quite a while ago, so my memory might be a bit rusty.
If you want to get a quick result on a single file, the cvs log command is good. If you want something more comprehensive, the best tool I've found for this is a perl script called cvs2cl.pl. This can generate a change list in several different formats. It has many different options, but I've used the tag-to-tag options like this:
cvs2cl.pl --delta dev_release_1_2_3:dev_release_1_6_8
or
cvs2cl.pl --delta dev_release_1_2_3:HEAD
I have also done comparisons using dates with the same tool.
I know you have already "solved" your problem, but I had the same problem and here is how I quickly got all of the comments out of cvs from a given revision until the latest:
$ mkdir ~/repo
$ cd ~/repo
$ mkdir cvs
$ cd cvs
$ scp -pr geek#avoid.cvs.org:/cvs/CVSROOT .
$ mkdir -p my/favorite
$ cd my/favorite
$ scp -pr geek#avoid.cvs.org:/cvs/my/favorite/project .
$ cd ~/repo
$ mkdir -p ~/repo/svn/my/favorite/project
$ cvs2svn -s ~/repo/svn/my/favorite/project/src ~/repo/cvs/my/favorite/project/src
$ mkdir ~/work
$ cd ~/work
$ svn checkout file:///home/geek/repo/svn/my/favorite/project/src/trunk ./src
$ cd src
$ # get the comments made from revision 5 until today
$ svn log -r 5:HEAD
$ # get the comments made from 2010-07-03 until today
$ svn log -r {2010-07-03}:HEAD
The basic idea is to just use svn or git instead of cvs :-)
And that can be done by converting the cvs repo to svn or git using cvs2svn or cvs2git, which we should be doing anyway. It got my my answer within about three minutes because I had a small repository.
Hope that helps.
Something like this
cvs -q log -NS -rVERSION_3_0::HEAD
Where you probably want to pipe the output into egrep to filter out the stuff you don't want to see. I've used this:
cvs -q log -NS -rVERSION_3_0::HEAD | egrep -v "RCS file: |revision |date:|Working file:|head:|branch:|locks:|access list:|keyword substitution:|total revisions: |============|-------------"