Skip to content

Commit

Permalink
linearize: tweak git clean check to linearize instead of in hook
Browse files Browse the repository at this point in the history
  • Loading branch information
zegl committed Oct 5, 2023
1 parent 0000057 commit 0000058
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions git-linearize
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ function git_has_linearize_root() {
fi
}

function git_is_ready() {
# current directory has changes to tracked files
if git status --porcelain | grep -v -q "??"; then
return 1
fi

# no changes, or only changes to untracked files
return 0
}

########################################################################################################################
# Dependencies check #
########################################################################################################################
Expand Down Expand Up @@ -169,15 +179,7 @@ function cmd_install_hook() {

cat >"$FILE" <<-EOM
#!/bin/bash
if ! git_status_output="$(git status --porcelain)"; then
error_code="$?"
echo "'git status' had an error: $error_code"
elif [ -z "$git_status_output" ]; then
echo "Working directory is clean, linearizing"
git-linearize ${FORWARD_IF_BRANCH} ${FORWARD_FORMAT}
else
echo "Working directory has UNCOMMITTED CHANGES.\nNot running git-linearize yet"
fi
git linearize ${FORWARD_IF_BRANCH} ${FORWARD_FORMAT}
EOM
chmod +x "$FILE"

Expand All @@ -197,6 +199,12 @@ function cmd_linearize() {
exit 0
fi

if ! git_is_ready; then
echoerr "[x] The current git directory is not clean. Skipping. :-)"
echoerr " Don't worry, git linearize will clean up all commits all at once later."
exit 0
fi

if git_has_linearize_root; then
found_root=$(find_root_on_current_branch)
echodebug "[x] Repository has a custom root commit (${found_root}), using it as the root"
Expand Down

0 comments on commit 0000058

Please sign in to comment.