Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [`git clear-soft`](#git-clear-soft)
- [`git coauthor`](#git-coauthor)
- [`git commits-since`](#git-commits-since)
- [`git continue`](#git-continue)
- [`git contrib`](#git-contrib)
- [`git count`](#git-count)
- [`git cp`](#git-cp)
Expand Down Expand Up @@ -415,9 +416,9 @@ $ git coauthor user [email protected]
2 files changed, 145 insertions(+), 0 deletions(-)
create mode 100644 README.md
create mode 100644 CONTRIBUTING.md

$ git log -1

commit b62ceae2685e6ece071f3c3754e9b77fd0a35c88 (HEAD -> master)
Author: user person <[email protected]>
Date: Sat Aug 17 17:33:53 2019 -0500
Expand Down Expand Up @@ -1368,7 +1369,7 @@ Switched to branch 'mr/51'
With full URL, the head is fetched from a temporary remote pointing to the base URL.

``` bash
$ git mr https://gitlab.com/owner/repository/merge_requests/51
$ git mr https://gitlab.com/owner/repository/merge_requests/51
From gitlab.com:owner/repository
* [new ref] refs/merge-requests/51/head -> mr/51
Switched to branch 'mr/51'
Expand Down Expand Up @@ -1623,3 +1624,7 @@ Abort current revert, rebase, merge or cherry-pick, without the need to find exa
## git magic

Commits changes with a generated message.

## git continue

Continue current revert, rebase, merge or cherry-pick, without the need to find exact command in history.
51 changes: 38 additions & 13 deletions bin/git-abort
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
#!/usr/bin/env bash

gitdir="$(git rev-parse --git-dir)" || exit
opfound=
fcnt=
for i in cherry-pick merge rebase revert; do
f=${i^^}
f=${f/-/_}
test -f "${gitdir}/${f}_HEAD" && fcnt=1$fcnt && opfound=$i
done
set -euo pipefail

if [ "${fcnt}" != 1 ]; then
echo "I don't know what to abort" >&2
exit 1
fi
function discover_op() {
local gitdir
# git rev-parse emits an error if not in a git repo so only need to bail out
gitdir="$(git rev-parse --git-dir)" || exit
local op
for op in cherry_pick merge rebase revert ; do
if [ -f "${gitdir}/${op^^}_HEAD" ]; then
echo "${op/_/-}"
fi
done
}

git "${opfound}" --abort
function validate_op() {
local op="$1"
if [ -z "$op" ]; then
echo "No active operation found" >&2
exit 1
fi
if [[ "$(echo "$op" | wc -l)" -gt 1 ]]; then
echo "Multiple active operations found: $op" >&2
exit 1
fi
}

function discover_action() {
Copy link
Collaborator

@hyperupcall hyperupcall Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of this function (feel like there is a better way to go about this), but I'm good with this for now.

local action=${1/git-/}
if [ "$action" != "abort" ] && [ "$action" != "continue" ]; then
echo "Invalid action: $1" >&2
exit 1
fi
echo "$action"
}

action=$(discover_action "$(basename "$0")")
op=$(discover_op)
validate_op "$op"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am reading the code correctly, if validate_op fails, then the script does not exit early (and the git command will erroneously execute) because errexit is not set. (the same is the case with discover_action). I think errexit should be set at the top?


git "$op" "--$action"
1 change: 1 addition & 0 deletions bin/git-continue
1 change: 1 addition & 0 deletions etc/git-extras-completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \
clear:'rigorously clean up a repository' \
coauthor:'add a co-author to the last commit' \
commits-since:'show commit logs since some date' \
continue:'continue current revert, merge, rebase, or cherry-pick process' \
contrib:'show user contributions' \
count:'show commit count' \
create-branch:'create branches' \
Expand Down
19 changes: 19 additions & 0 deletions man/git-continue.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.\" generated with Ronn-NG/v0.8.0
.\" http://github.com/apjanke/ronn-ng/tree/0.8.0
.TH "GIT\-CONTINUE" "1" "November 2024" "" "Git Extras"
.SH "NAME"
\fBgit\-continue\fR \- Continue current git operation
.SH "SYNOPSIS"
\fBgit\-continue\fR
.SH "DESCRIPTION"
Continue current git revert, rebase, merge or cherry\-pick process\.
.SH "OPTIONS"
There are no options, it just continues current operation\.
.SH "EXAMPLES"
\fBgit\-continue\fR
.SH "AUTHOR"
Written by oikarinen
.SH "REPORTING BUGS"
<\fI\%https://github\.com/tj/git\-extras/issues\fR>
.SH "SEE ALSO"
<\fI\%https://github\.com/tj/git\-extras\fR>
114 changes: 114 additions & 0 deletions man/git-continue.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions man/git-continue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
git-continue(1) -- Continue current git operation
================================

## SYNOPSIS

`git-continue`

## DESCRIPTION

Continue current git revert, rebase, merge or cherry-pick process.

## OPTIONS

There are no options, it just continues current operation.

## EXAMPLES

`git-continue`

## AUTHOR

Written by oikarinen

## REPORTING BUGS

&lt;<https://github.com/tj/git-extras/issues>&gt;

## SEE ALSO

&lt;<https://github.com/tj/git-extras>&gt;
2 changes: 2 additions & 0 deletions man/git-extras.1
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Change the default branch to \fB$BRANCH\fR\. If \fBgit\-extras\.default\-branch\
.IP "\[ci]" 4
\fBgit\-commits\-since(1)\fR Show commit logs since some date
.IP "\[ci]" 4
\fBgit\-continue(1)\fR Continue current git operation
.IP "\[ci]" 4
\fBgit\-contrib(1)\fR Show user's contributions
.IP "\[ci]" 4
\fBgit\-count(1)\fR Show commit count
Expand Down
4 changes: 3 additions & 1 deletion man/git-extras.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/git-extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ git-extras(1) -- Awesome GIT utilities
- **git-clear(1)** Rigorously clean up a repository
- **git-coauthor(1)** Add a co-author to the last commit
- **git-commits-since(1)** Show commit logs since some date
- **git-continue(1)** Continue current git operation
- **git-contrib(1)** Show user's contributions
- **git-count(1)** Show commit count
- **git-cp(1)** Copy a file keeping its history
Expand Down
1 change: 1 addition & 0 deletions man/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ git-clear(1) git-clear
git-coauthor(1) git-coauthor
git-commits-since(1) git-commits-since
git-contrib(1) git-contrib
git-continue(1) git-continue
git-count(1) git-count
git-cp(1) git-cp
git-create-branch(1) git-create-branch
Expand Down
3 changes: 2 additions & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ It is done or go without `poetry`,
1. Install python >= 3.11
2. Install pytest >= 8.1.2
3. Install gitpython >= 3.1.43
4. Run `pytest`
4. Install testpath >= 0.6.0
5. Run `pytest`

The second way maybe blocked the some missing dependencies at someday, so the first one is recommended.

Expand Down
12 changes: 10 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

def create_repo(dirname=None):
repo = TempRepository(dirname)
repo.create_tmp_file()
repo.create_tmp_file()
repo.create_tmp_file() # tmp_file_a
repo.create_tmp_file() # tmp_file_b
repo.switch_cwd_under_repo()
return repo

Expand All @@ -35,3 +35,11 @@ def named_temp_repo(request):
init_repo_git_status(repo)
yield repo
repo.teardown()


@pytest.fixture(scope="function")
def temp_repo_clean():
"""Create a temporary repository that is reset for each function call."""
repo = create_repo()
init_repo_git_status(repo)
return repo
Loading
Loading