Code Monkey home page Code Monkey logo

git-tools's Introduction

Git Tools

Assorted git-related scripts and tools

Requirements

  • Git (duh!). Tested in v2.17.1 and prior versions since 2010
  • Python (for git-restore-mtime). Tested in Python 3.6, also works in Python 3.1+
  • Bash (for all other tools). Tested in Bash 4, some may work in Bash 3 or even sh

Bash and Python are already installed by default in virtually all GNU/Linux distros. And you probably already have Git if you are interested in these tools. If needed, the command to install dependencies for Debian-like distros (like Ubuntu/Mint) is:

sudo apt install bash python3 git

Installation

For Debian, Ubuntu, LinuxMint, and their derivatives, in official repositories as git-restore-mtime:

sudo apt install git-restore-mtime

For Fedora and in EPEL repository for CentOS, Red Hat Enterprise Linux (RHEL), Oracle Linux and others, as root:

dnf install git-tools  # 'yum' if using older CentOS/RHEL releases

Gentoo and Funtoo, also as root:

emerge dev-vcs/git-tools

Arch Linux:

sudo pacman -S git-tools-git

Homebrew:

brew install git-tools

MacPorts:

sudo port install git-tools

Also available in Kali Linux, MidnightBDS mports, Mageia, and possibly other distributions.

GitHub Actions: (git-restore-mtime only)

build:
    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0
    - uses: chetan/git-restore-mtime-action@v2

Manual install: to run from the repository tree, just clone and add the installation directory to your $PATH:

cd ~/some/dir
git clone https://github.com/MestreLion/git-tools.git
echo 'PATH=$PATH:~/some/dir/git-tools' >> ~/.profile  # or ~/.bashrc

To install the man pages, simply copy (or symlink) the files from man1/ folder to ~/.local/share/man/man1, creating the directory if necessary:

dest=${XDG_DATA_HOME:$HOME/.local/share}/man/man1
mkdir -p -- "$dest"
cp -t "$dest" -- ~/some/dir/git-tools/man1/*.1  # or `ln -s -t ...`

Usage

If you installed using your operating system package manager, or if you added the cloned repository to your $PATH, you can simply run the tools as if they were regular git subcommands! For example:

git restore-mtime --test

The magic? Git considers any executable named git-* in either /usr/lib/git-core or in $PATH to be a subcommand! It also integrates with man, triggering the manual pages if they're installed, such as when installing using your package manager:

git restore-mtime --help
git help strip-merge

In case the manual pages are not installed in the system, such as when running from the cloned repository, you can still read the built-in help by directly invoking the tool:

git-clone-subset --help

Uninstall

For the packaged versions, use your repository tools such as apt, brew, emerge, or yum.

For manual installations, delete the directory, manpages, and remove it from your $PATH.

rm -rf ~/some/dir/git-tools  # and optionally ~/.local/share/man/man1/git-*.1
sed -i '/git-tools/d' ~/.profile

Tools

This is a brief description of the tools. For more detailed instructions, see --help of each tool.

git-branches-rename

Batch renames branches with a matching prefix to another prefix

Examples:

$ git-rename-branches bug bugfix
bug/128  -> bugfix/128
bug_test -> bugfix_test

$ git-rename-branches ma backup/ma
master -> backup/master
main   -> backup/main

git-clone-subset

Clones a subset of a git repository

Uses git clone and git filter-branch to remove from the clone all but the requested files, along with their associated commit history.

Clones a repository into a destination directory and runs git filter-branch --prune-empty --tree-filter 'git rm ...' -- --all on the clone to prune from history all files except the ones matching a pattern, effectively creating a clone with a subset of files (and history) of the original repository.

Useful for creating a new repository out of a set of files from another repository, migrating (only) their associated history. Very similar to what git filter-branch --subdirectory-filter does, but for a file pattern instead of just a single directory.

git-find-uncommitted-repos

Recursively list repos with uncommitted changes

Recursively finds all git repositories in the given directory(es), runs git status on them, and prints the location of repositories with uncommitted changes. The tool I definitely use the most.

git-rebase-theirs

Resolve rebase conflicts and failed cherry-picks by favoring 'theirs' version

When using git rebase, conflicts are usually wanted to be resolved by favoring the working branch version (the branch being rebased, 'theirs' side in a rebase), instead of the upstream version (the base branch, 'ours' side). But git rebase --strategy -X theirs is only available from git 1.7.3. For older versions, git-rebase-theirs is the solution. Despite the name, it's also useful for fixing failed cherry-picks.

git-restore-mtime

Restore original modification time of files based on the date of the most recent commit that modified them

Probably the most popular and useful tool, and the reason this repository was packaged into distros.

Git, unlike other version control systems, does not preserve the original timestamp of committed files. Whenever repositories are cloned, or branches/files are checked out, file timestamps are reset to the current date. While this behavior has its justifications (notably when using make to compile software), sometimes it is desirable to restore the original modification date of a file (for example, when generating release tarballs). As git does not provide any way to do that, git-restore-mtime tries to work around this limitation.

For more information and background, see http://stackoverflow.com/a/13284229/624066

For TravisCI users, simply add this setting to .travis.yml so it clones the full repository history:

git:
  depth: false

Similarly, when using GitHub Actions, make sure to include fetch-depth: 0 in your checkout workflow, as described in its documentation:

- uses: actions/checkout@v2
  with:
    fetch-depth: 0

git-strip-merge

A git-merge wrapper that delete files on a "foreign" branch before merging

Answer for "How to set up a git driver to ignore a folder on merge?", see http://stackoverflow.com/questions/3111515

Example:

$ git checkout master
$ git-strip-merge design photoshop/*.psd

Contributing

Patches are welcome! Fork, hack, request pull!

If you find a bug or have any enhancement request, please open a new issue

Author

Rodrigo Silva (MestreLion) [email protected]

License and Copyright

Copyright (C) 2012 Rodrigo Silva (MestreLion) <[email protected]>.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

git-tools's People

Contributors

algorythmic avatar artyl avatar chrisfinazzo avatar dankm avatar dwfreed avatar floppym avatar gebailey avatar hakuna75 avatar kilobyte avatar mestrelion avatar osemenovboyarka avatar rasa avatar shuber2 avatar sysvinit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

git-tools's Issues

statistics are given in STDERR not STDOUT

Running git-restore-mtime gives something like this:

Statistics:
         2.28 seconds
       61,827 log lines processed
        7,790 commits evaluated
           54 directory update errors
           34 directories updated
        7,758 files
        3,609 file update errors
        4,149 files updated

However, doing git-restore-mtime 2>/dev/null to discard STDERR gives no output.

The statistics should not be hidden there.

Timestamp

sudo apt install git-restore-mtime # Debian, Ubuntu, and Linux Mint yum install git-tools # Fedora, Red Hat Enterprise Linux (RHEL), and CentOS emerge dev-vcs/git-tools

Problem inside Python 'check_arg_types'

Hello,

since about 2 days, I have a problem running "git restore-mtime". Before then, it worked well. I suspect this is an issue with a very recent update of my Python version to 3.7.13. Let me show the error:

$ cd $HOME/build/pencil-code/pencil-code/ && git restore-mtime src/
Traceback (most recent call last):
  File "/usr/lib/git-core/git-restore-mtime", line 157, in <module>
    lsfileslist.add(os.path.relpath(line.strip(), workdir))
  File "/opt/pyenv/versions/3.7.13/lib/python3.7/posixpath.py", line 485, in relpath
    genericpath._check_arg_types('relpath', path, start)
  File "/opt/pyenv/versions/3.7.13/lib/python3.7/genericpath.py", line 155, in _check_arg_types
    raise TypeError("Can't mix strings and bytes in path components") from None
TypeError: Can't mix strings and bytes in path components

PS: This happens when using ubuntu 16.04 (default on Travis!). I switched to using ubuntu 20.04 now and it works again...
It would be great if you could have a look, since many people use Travis builds in their default configuration.

Thanks and best greetings!

NameError: global name 'filterlist' is not defined

When I run the latest version of git-restore-mtime-core, in a git repository checkout, I get the following error:

Traceback (most recent call last):
  File "/home/ross/bin/git-restore-mtime-core", line 114, in <module>
    parselog(args.merge)
  File "/home/ross/bin/git-restore-mtime-core", line 86, in parselog
    (['-m'] if merge else []) + filterlist,
NameError: global name 'filterlist' is not defined

What am I doing wrong?

Thanks!

invalid macro in manpage

manpage-has-errors-from-man usr/share/man/man1/git-clone-subset.1.gz 54: warning: macro `!(<pattern>)'' not defined

A --skip option for restore-mtime?

Would a --skip option to restore-time be useful?
So not forcing the author/commit time on the uncommited files, but just letting them keep the more recent mtime.
That would seem a more logical approach.

git-restore-mtime ignore modified files in working directory

git-utimes ignores files that are modified in the working directory. I think this is good default behavior. With git-restore-mtime, your only options are to abort (do nothing) or --force and then your modified working directory files have their times set to the commit date, which seems like a bad outcome to me. I'd prefer if git-restore-mtime just didn't touch modified files in the working directory, while perhaps letting the user know that the --force option is available if required.

Directory mtime support

Hi!

Thanks so much for writing these tools (git-restore-mtime in particular).

Any chance you can add support for also setting the mtime of the directory? (e.g. to the latest mtime of any file within it?)

git-restore-mtime not actually installing

I've installed with sudo apt and the executable is still not present.

(rstudio) balter@little-d:~$ sudo apt install git-restore-mtime
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  git-restore-mtime
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 15.8 kB of archives.
After this operation, 50.2 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu cosmic/universe amd64 git-restore-mtime all 2017.10-1 [15.8 kB]
Fetched 15.8 kB in 1s (25.3 kB/s)
Selecting previously unselected package git-restore-mtime.
(Reading database ... 55777 files and directories currently installed.)
Preparing to unpack .../git-restore-mtime_2017.10-1_all.deb ...
Unpacking git-restore-mtime (2017.10-1) ...
Setting up git-restore-mtime (2017.10-1) ...
Processing triggers for man-db (2.8.4-2) ...
(rstudio) balter@little-d:~$ which git-restore-mtime
(rstudio) balter@little-d:/usr/bin$ find . -name "*mtime"
(rstudio) balter@little-d:/usr/bin$

RFC: Allow silencing warnings (and perhaps errors)

As pointed out by @t0mm1e in #52, --quiet does not silence warnings, and there's no way to do so (apart from 2>/dev/null, which would also silence errors.

We have a few options here:

  • Change --quiet to also silence warnings. Is this desired behavior? Should it also silence errors? Is it worth breaking current behavior?
  • Add a new option, such as --silent or --mute, to extend silence to warnings. This is the approach taken by, IIRC, curl or wget. What is the preferred name? Should it also silence errors? If not, should a 3rd option do so?

I'll leave this one open for user feedback and comments on the best way to implement this.

Won't work inside TravisCI

First of all thanks for this script, works great in local environments but I simply for the life of me cannot get git-restore-mtime to work inside a TravisCI environment. Has anyone had any success with using this in TravisCI ??

My issue is being able to get the last modified dates and times correct of certain files in the repo so that they can be written into README.md when I build so that users can look through my page of stats and easily when a certain list I create was last updated.

Homebrew support

Can you please support installation via homebrew for macos? The restore mtime script is super awesome, but I prefer to install all applications/libraries/tools via homebrew, and so would prefer this.

git-restore-mtime cuts last character from ignored/untracked files

In git-restore-mtime, in the code for finding untracked and ignored files, filespec = line[3:-1] cuts off the last character of filenames. This affects repos where there are e.g. editor backup files, such as "file~". In this case, "file" is added to the list of files that are left untouched by the script. The -1 is not necessary together with line.strip().

restore-mtime: AttributeError: 'Git' object has no attribute '_proc'

git-restore-mtime prints a stack trace when it is in a folder without a .git subfolder.

~/bin/git-restore-mtime
Exception ignored in: <function Git.__del__ at 0x7efd82eb01f0>
Traceback (most recent call last):
  File "/home/willem/bin/git-restore-mtime", line 364, in __del__
    self.terminate()
  File "/home/willem/bin/git-restore-mtime", line 331, in terminate
    if self._proc is None:
AttributeError: 'Git' object has no attribute '_proc'

To reproduce: copy git-restore-mtime to another folder that does not contain a .git folder and run that copy or delete the git-tools/.git folder.

Python 3.10.5. Git 2.37.1. Arch Linux.

This did not happen in an older version (commit g12202fd).

(I created a git-tools (development) package in the Arch Linux AUR: https://aur.archlinux.org/packages/git-tools-git.)

fatal: mmap failed: Cannot allocate memory

After running on huge repositories (only seen on Linux Kernel), it may output the following error:

fatal: mmap failed: Cannot allocate memory

It doesn't seem to affect the script, and all processing and file/dir touches seem to be successful. After the first run, git somehow consider the repository "unclean" (and hence the script cannot run again), and any trivial git command takes several seconds to complete and outputs this error again.

Running git status seems to fix everything: the repository is considered "clean" again, git operations take their regular time, and the error message is gone.

git-restore-mtime fails on python 3 (3.4 and 3.5)

I've packaged git-tools for Fedora and am now receiving bugzilla reports related to Python 3:
https://bugzilla.redhat.com/show_bug.cgi?id=1322472

I've created a sample git repo and am attempting to use git-restore-mtime on it using various python interpreters.

When running git-restore-mtime using the Python 3.4 interpreter, I get:

[gbailey@spock test]$ python3.4 -V
Python 3.4.4
[gbailey@spock test]$ python3.4 /usr/bin/git-restore-mtime 
Traceback (most recent call last):
  File "/usr/bin/git-restore-mtime", line 165, in <module>
    lsfileslist.add(os.path.relpath(line.strip(), workdir))
  File "/usr/lib64/python3.4/posixpath.py", line 448, in relpath
    start_list = [x for x in abspath(start).split(sep) if x]
TypeError: Can't convert 'bytes' object to str implicitly

When running git-restore-mtime using the Python 3.5 interpreter, I get:

[gbailey@spock test]$ python3.5 -V
Python 3.5.1
[gbailey@spock test]$ python3.5 /usr/bin/git-restore-mtime 
Traceback (most recent call last):
  File "/usr/bin/git-restore-mtime", line 165, in <module>
    lsfileslist.add(os.path.relpath(line.strip(), workdir))
  File "/usr/lib64/python3.5/posixpath.py", line 459, in relpath
    genericpath._check_arg_types('relpath', path, start)
  File "/usr/lib64/python3.5/genericpath.py", line 145, in _check_arg_types
    raise TypeError("Can't mix strings and bytes in path components") from None
TypeError: Can't mix strings and bytes in path components

SyntaxError: invalid syntax on Python 3.4.3

When executing the test on an older system (Ubuntu 14.04) with Python 3.4.3, the following occurs:

$ git restore-mtime --test
  File "/home/username/bin/git-tools/git-restore-mtime", line 356
    stdout: str = subprocess.check_output(cmdlist, **popen_args)
          ^
SyntaxError: invalid syntax

Change the mtime milliseconds/microseconds to the git commit hash

We're using git-restore-mtime to let our build system know that a file has changed. Sometimes, two commits might happen at exactly the same time, making the files changed wrongly have the same mtime, and thus the build system doesn't rebuild them, even though they've changed.

I propose that, since git only has second-accuracy, the milliseconds/microseconds field be set to the first bits of the commit hash. That way, files on different commits will never match, even if they were committed on the same second.

Option not to touch files with earlier date/time

Thanks for the git-restore-mtime tool!

I think it would be useful if files with earlier date/times than the commit time could be skipped. That way the original file date/time history for files that are in the original source directory they came from could be preserved.

Add sources for man pages in a convenient format

As command-line options for the tools grow and change, specially in restore-mtime, the man pages inevitably get outdated. Also, man pages (could) contain information and knowledge that do not really belong in a tool's --help but should be more visible than a source code comment, TODO or FIXME. For example, info about #38 could be added in a "Known Bugs" or "Limitations" section.

But editing man pages by hand is very difficult for those unfamiliar with nroff syntax (or is it groff? roff maybe?), myself included. It would be great if the project had such man pages in a format that's more easily editable, then converted to nroff using a tool in a build script.

Ideally such tool would also invoke the tool's --help to keep the man pages updated with current options. Preferably not enforcing a direct copy-and-paste but allowing a more detailed, expanded description on each option, while deleting obsolete and warning on any missing ones.

For those familiar with such workflow (@kilobyte , @dwfreed ?), what are the current/suggested standards? Markdown, AsciiDoc, something else? Any suggestions on how I should implement this in this project? @gebailey , as the author of current man pages, how did you create them? By hand? Did you use any tools to generate them from a template/--help or to automate the process in any way?

I'm completely unfamiliar with this whole thing, so any directions are much appreciated!

Reported mtime is not the last modifying commit in the case of merges

I'm the author of git-warp-time, a CLI implemented in Rust that does much the same job as git-restore-mtime. It looks like your project predates mine by quite a while. I remember spending quite a while looking for existing solutions before implementing mine and coming up blank. I probably wouldn't have written anything if I had found this, but here we are. Now that I've been made aware of it I figured I'd put it through some paces and see how it stacks up. I was surprised at how fast it ran, so good work on that front!

That being said I noticed that it was resetting times to quite different values than git warp-time and alternating between that and git restore-mtime was just playing tug of war. It seems like git restore-mtime touches all the files in the repository no matter whether it is necessary or not, but since git warp-time touches and reports on only files that needed changing I would have expected it to settle down to no-changes needed in that direction.

I dug into it a bit and it turns out the commit graph is being processed differently, and git restore-mtime is not taking into account merge commits that affect files in the target branch. It is using the commit time of the last commit in the source branch or merge base rather than the actual merge commit. This results in an incorrect modification time since the merge commit itself actually modifies the file on disk. This is especially relevant when the merge has conflict resolution or the default branch had chronologically newer data than the merge source branch.

Attached is a git repo with such a history as an example that can be extracted with gunzip and then git unbundle: merge-history-example.bundle.gz

You can run each command on the repository then stat test-file to see the different modification dates being set.

I'm not too worried about a solution myself because at this point I'm satisfied with git warp-time and will continue using (and maintaining) it, but I thought it might be useful to report the issue here anyway in case it affects others and you want to fix it.

Time zone support

I use git-restore-mtime.py with the Hugo generator to restore an post's edit time from Git information. The effect is very good, great script👍.

But git-restore-mtime.py seems to restore UTC time, right? I added time zone to the system environment where this script is executed, but it had no effect.
Is it possible to add a time zone parameter to offset the time according to the user-specified time zone when setting the mtime of the file?

[restore-mtime] Add instructions for GitHub Actions in documentation

Here is the data I can share....

locally it works fine the output shows:

36 files to be processed in work dir
Statistics:
         0.02 seconds
          762 log lines processed
           73 commits evaluated
           36 updated files
            8 updated directories

On github action it shows:

36 files to be processed in work dir
Statistics:
         0.02 seconds
           38 log lines processed
            1 commits evaluated
           36 updated files
           10 updated directories

As we can see there are a lot less log lines processed in the pipeline
I get a feeling this might be similar to Issue #29

UTF-8 Error

If i try to execute the command 'git restore-mtime --test' i get this error:

Traceback (most recent call last):
File "/usr/lib/git-core/git-restore-mtime", line 594, in
sys.exit(main())
^^^^^^
File "/usr/lib/git-core/git-restore-mtime", line 530, in main
parse_log(filelist, dirlist, stats, git, args.merge, args.pathspec)
File "/usr/lib/git-core/git-restore-mtime", line 410, in parse_log
file = normalize(file)
^^^^^^^^^^^^^^^
File "/usr/lib/git-core/git-restore-mtime", line 254, in normalize
.decode('utf8')) # Decode from UTF-8
^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 38: invalid continuation byte

Error on dangling symlinks

git-restore-mtime gives error on dangling symlinks. It should detect and skip them without errors or warnings.

And maybe git-restore-mtime should not operate on symlinks at all. Create an option for that?

Sparse checkout excluded files & folders not ignored by -s flag

Reproducer steps:

git clone --depth=1 https://github.com/chromebrew/chromebrew.git test
cd test
git sparse-checkout set packages manifest/x86_64 lib commands bin crew tests tools
git-restore-mtime -s 

I get this output:

7,762 files to be processed in work dir
ERROR: [Errno 2] No such file or directory: .github/ISSUE_TEMPLATE/bug_report.md
ERROR: [Errno 2] No such file or directory: .github/ISSUE_TEMPLATE
ERROR: [Errno 2] No such file or directory: .github/ISSUE_TEMPLATE/config.yml
ERROR: [Errno 2] No such file or directory: .github/PULL_REQUEST_TEMPLATE.md
ERROR: [Errno 2] No such file or directory: .github
ERROR: [Errno 2] No such file or directory: .github/workflows/Handoff.yml
ERROR: [Errno 2] No such file or directory: .github/workflows
ERROR: [Errno 2] No such file or directory: .github/workflows/Markdown-lint.yml
ERROR: [Errno 2] No such file or directory: .github/workflows/Repology.yml
ERROR: [Errno 2] No such file or directory: .github/workflows/Rubocop.yml
ERROR: [Errno 2] No such file or directory: .github/workflows/ShellCheck.yml
ERROR: [Errno 2] No such file or directory: .github/workflows/Unit-Test.yml
ERROR: [Errno 2] No such file or directory: .github/workflows/YAMLlint.yml
ERROR: [Errno 2] No such file or directory: images/brew.png
ERROR: [Errno 2] No such file or directory: images
ERROR: [Errno 2] No such file or directory: images/discord.svg
ERROR: [Errno 2] No such file or directory: images/slack.svg
ERROR: [Errno 2] No such file or directory: manifest/armv7l/a/a2png.filelist
ERROR: [Errno 2] No such file or directory: manifest/armv7l/a
ERROR: [Errno 2] No such file or directory: manifest/armv7l/a/a2ps.filelist
ERROR: [Errno 2] No such file or directory: manifest/armv7l/a/aalib.filelist
ERROR: [Errno 2] No such file or directory: manifest/armv7l/a/abcde.filelist
ERROR: [Errno 2] No such file or directory: manifest/armv7l/a/abcl.filelist
ERROR: [Errno 2] No such file or directory: manifest/armv7l/a/abseil_cpp.filelist
...
ERROR: [Errno 2] No such file or directory: manifest/i686/z/zziplib.filelist
ERROR: [Errno 2] No such file or directory: manifest/i686/z/zzuf.filelist
Statistics:
         0.16 seconds
        7,764 log lines processed
            1 commits evaluated
           56 directory update errors
           35 directories updated
        7,762 files
        3,465 file update errors
        4,297 files updated

The errors are all from the sparse-checkout excluded files. Is there a way to avoid erroring on those files?

Timestamps just default to whatever last commit time (regardless of the files changed in that commit)

Hi,

I'm running this:

git init
git config core.sparseCheckout true
git sparse-checkout set 'dir1/' 'dir2/'
git remote add origin https://${{ inputs.token }}@myowndomain.com/gitea/organization/${{ inputs.repository }}.git
git fetch --depth=1 origin master
git checkout master

And then another step where I do:

git fetch --prune --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*

chmod +x $GITHUB_ACTION_PATH/git-restore-mtime

$GITHUB_ACTION_PATH/git-restore-mtime -v

(I tried with and without the git fetch command in the second block above)

The problem is that git-restore-mtime basically just puts the timestamp of the last commit on that repository, regardless of the file.

Any ideas what I'm doing wrong? :)

Thank you very much!

git-restore-mtime doesn't work on subdirectories when running under Windows

When I run the script under Windows, only the files in the root directory of the repository are processed.

This is caused because of the use in backslashes in windows in stead of forward slashes; this causes a mismatch when comparing it to the git log.

I have fixed this for myself. I'm still learning how to use Git, so I'm not sure what the best way is of communicating my patch.

For now I've just pasted the contents of my patch file here:

From eae69f4a41c6eb57ebf31bb1b3d7898fe6e06103 Mon Sep 17 00:00:00 2001
From: Remco Voogt [email protected]
Date: Mon, 14 Oct 2013 08:51:09 +0200
Subject: [PATCH] Fix so the git-restore-mtime script also runs under
Windows for files in subdirectories.

Always use a forward slash when adding files to the list of relative paths, because Git always uses forward slashes.

git-restore-mtime | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/git-restore-mtime b/git-restore-mtime
index da92ecd..e64f86b 100755
--- a/git-restore-mtime
+++ b/git-restore-mtime
@@ -165,7 +165,8 @@ for path in args.pathspec:

         for file in files:
             # Always add them relative to worktree root
  •            filelist.add(os.path.relpath(os.path.join(root, file), workdir))
    
  •            relativefilepathwithforwardslash = os.path.relpath(os.path.join(root, file), workdir).replace("\", "/")
    
  •            filelist.add(relativefilepathwithforwardslash)
    

    totalfiles = files = len(filelist)

    logger.info("{:,} files to be processed in work dir".format(totalfiles))

    1.8.3.msysgit.0

Problem with default value of --git-dir parameter

According to git-restore-mtime --git-dir parameter help, its default is <work-tree-root>/.git
In case running the utility not from a git work-tree and supplying --work-tree parameter, current logic still tries to find the git repository under the current dir instead of <work-tree-root>/.git
To fix this i changed the last line of parse_args() function from "return parser.parse_args()" to the following lines:

args = parser.parse_args()
if args.workdir and not args.gitdir:
    # set default git repository path
    args.gitdir = os.path.join(args.workdir, '.git')

return args

normalize file path exception 'utf-8' codec can't decode byte 0xe1 in position 7: invalid continuation byte, input_file_path: "Get_krv\341canie_LMWH.ipynb"

I got this error while trying git commit with precommit hook

git-restore-mtime -v 

filename is

Get_krvácanie_LMWH.ipynb

escaped as

Get_krv\341canie_LMWH.ipynb

Whole error is:

Traceback (most recent call last):
  File "/usr/lib/git-core/git-restore-mtime", line 413, in <module>
    sys.exit(main())
  File "/usr/lib/git-core/git-restore-mtime", line 368, in main
    parselog(filelist, dirlist, stats, git, args.merge, args.pathspec)
  File "/usr/lib/git-core/git-restore-mtime", line 274, in parselog
    file = normalize(file)
  File "/usr/lib/git-core/git-restore-mtime", line 189, in normalize
    .decode('utf8'))           # Decode from UTF-8
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 7: invalid continuation byte
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 153, in apport_excepthook
    with os.fdopen(os.open(pr_filename,
FileNotFoundError: [Errno 2] No such file or directory: '/var/crash/_usr_lib_git-core_git-restore-mtime.1000.crash'

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/git-core/git-restore-mtime", line 413, in <module>
    sys.exit(main())
  File "/usr/lib/git-core/git-restore-mtime", line 368, in main
    parselog(filelist, dirlist, stats, git, args.merge, args.pathspec)
  File "/usr/lib/git-core/git-restore-mtime", line 274, in parselog
    file = normalize(file)
  File "/usr/lib/git-core/git-restore-mtime", line 189, in normalize
    .decode('utf8'))           # Decode from UTF-8
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 7: invalid continuation byte

I can recreate the error in python console:

path = "\"Get_krv\341canie_LMWH.ipynb\""
path = (path[1:-1].encode('latin1').decode('unicode-escape')) 
path
#'Get_krvácanie_LMWH.ipynb'
path.encode('latin1').decode('utf8')
#Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
#UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 7: invalid continuation byte

Python 3: " str doesn't support the buffer API "

Python 3.3.3 on Windows 7:

$ python ./git-restore-mtime
Traceback (most recent call last): File "./git-restore-mtime", line 122, in 'git rev-parse --show-toplevel --git-dir')).split('\n')[:2] TypeError: Type str doesn't support the buffer API

As reported here:
http://stackoverflow.com/questions/2179722/checking-out-old-file-with-original-create-modified-timestamps/13284558?noredirect=1#comment31556810_13284558

Thanks for your work!
Let me know if you need more information, I could run tests again.

How do I use this on Windows?

I have Python and GIT. I really want to restore meta info when I checkout branches. Do I need to register this script as a pre-hook with git? How do I use this thing? I promise to share your the solution on StackOverflow

git-restore-mtime : Restore timestamp from remote repository.

The current git-restore-mtime does not work if you have only cloned the remote repository to a limited depth: as in git clone --depth 1 https://github.com/sanskrit-coders/stardict-sanskrit.git. It would be super if timestamp could be restored from the remote (say github) repository.

doco : add example of use, e.g. git restore-mtime

Documentation

With the ubuntu (and others?) packages, add scripts are (e.g.) /usr/lib/git-core/git-restore-mtime

cd [git repo]
/usr/lib/git-core/git-restore-mtime

Thanks for git-restore-mtime, 1000x faster than a git log script!

git-restore-mtime fails on Python 3 with non-ASCII filenames

The git-restore-mtime script fails when used in the following scenario:

  1. Windows with NTFS file system.
  2. Filename with UTF-8 characters. My concrete example: "Häuser.txt" with the German umlaut ä fails with the error message "WARNING: not found in log: Hõuser.txt" (you see how the error log message uses a different UTF-8 character, namely õ). Not sure if this happens for all UTF-8 characters, or just the ones that are available in the local 8bit codepage like äöü in Switzerland.

As I have no Python know how, I don't know how to debug/analyze the issue myself. Hope you can help.

btw: thanks for the script! I really like it.

Markus

git-find-uncommitted-repos: readlink problem

Hi; I downloaded git-tools because of git-restore-mtime, and thought I'd try some of the other jewels here (with MacOS Catalina 10.15.4).

Alas, Apple "thinks different", and the 'readlink' command doesn't have the -f option:

$ git find-uncommitted-repos
readlink: illegal option -- f
usage: readlink [-n] [file ...]
^C

Initially, I was going to suggest checking for the existence of 'greadlink' (GNU version, as installed by 'brew'), but when I looked at the code, it appears that the output of readlink is no longer used, and that line could be removed completely!
https://github.com/MestreLion/git-tools/blob/master/git-find-uncommitted-repos#L25

Thanks for writing these great tools!

Add bash completion scripts

Hello,

It would be nice to have bash auto complete either files or command just like any other git commands. I tried to look at git-completions, but it's hard to understand how it works.

By default, on Debian 12, "git rest" autocomplete to "git restore " and not "git restore" which means we have to backtrack one character (the space after restore) and then type "-mtime" manually. Afterwards, no completion occurs, neither for files nor for options.

I don't know if it's easily doable.
Thanks

Arch Linux instructions are wrong

sudo pacman -S git-tools-git

The AUR is a user repository of package definitions, not packages. These cannot be installed directly with pacman as these instructions suggest. You must either clone the repository and build the package yourself, then manually install the package file (officially recommended) or use an AUR helper that handles those steps automatically (officially not recommended but commonly used for convenience). In either case the command shown here is wrong. Also several references I've seen on stack overflow to this same effect are factually wrong.

The correct way to handle this is probably to just link the AUR packing page and let users use their preferred method.

Separately the AUR package definition is incorrectly setup, but I've commented on that issue there and is unrelated to this tracking issue.

Add tests for `restore-mtime`

restore-mtime is packaged in all major GNU/Linux distributions, for years, sometimes along other tools in this repository. It might have started as a proof-of-concept just to solve a StackOverflow question, but that's no longer the case. If Debian runs in the International Space Station, so can my little baby. It isn't a baby, or even "mine" anymore. it's a big boy now, and as such it deserves to step up.

Tests

Unit tests, coverage tests, CI tests. It needs testing. Any testing is better than current "-v in it's own repo seems fine, and it blazes the linux kernel's repo in about a minute without errors"

I appreciate the help of anyone more experienced in testing than myself. Which basically means anyone and everyone.

Suggestions, patches, PRs. Comments on where to start, or how it should be structured. Everything is welcome.

git-rebase-theirs

git-rebase-theirs uses tempfile, which is not available on all machines (at least not on my FC12 machine)

decode("string-escape") fails with python 3

Reported via Red Hat bugzilla:
https://bugzilla.redhat.com/show_bug.cgi?id=1748462

Reproduction (on Fedora 30 using Python 3.7.4):

[gbailey@localhost zxcv]$ git init
Initialized empty Git repository in /home/gbailey/zxcv/.git/
[gbailey@localhost zxcv]$ touch file1 "file2 with space" "\"file3"
[gbailey@localhost zxcv]$ git add .
[gbailey@localhost zxcv]$ git commit -m test
[master (root-commit) 9f05ab3] test
 3 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 "\"file3"
 create mode 100644 file1
 create mode 100644 file2 with space
[gbailey@localhost zxcv]$ git-restore-mtime 
2 files to be processed in work dir
Traceback (most recent call last):
  File "/usr/bin/git-restore-mtime", line 332, in <module>
    parselog(args.merge, args.pathspec)
  File "/usr/bin/git-restore-mtime", line 287, in parselog
    file = file[1:-1].decode("string-escape")
AttributeError: 'str' object has no attribute 'decode'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.