threads / patch / 2021

patchWrite .editmsg in GIT_DIR to avoid being in git-status.

Subject: [PATCH] Write .editmsg in GIT_DIR to avoid being in git-status.

## tl;dr

4 messages between Oct 5, 2005 and Oct 6, 2005. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Santi Béjar· Oct 5, 2005, 16:54 UTC · lore

It appears in the git-status output during a git-commit if you have something in info/exclude.

Also for .cmitmsg and .cmitchk to make git-commit work in read-only working trees.

Signed-off-by: Santi Béjar <sbejar@gmail.com>
---
 git-commit.sh |   24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)

applies-to: 9eec9ff9326032bca405a12a265918725edf4ac7 4e61f41c1feed7345fc442747c82b9ea701fb59c

Show changes to git-commit.sh +12 −12
diff --git a/git-commit.sh b/git-commit.sh
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -129,7 +129,7 @@ then
 elif test "$use_commit" != ""
 then
 	git-cat-file commit "$use_commit" | sed -e '1,/^$/d'
-fi | git-stripspace >.editmsg
+fi | git-stripspace >"$GIT_DIR"/.editmsg 
 
 case "$signoff" in
 t)
@@ -139,7 +139,7 @@ t)
 			s/>.*/>/
 			s/^/Signed-off-by: /
 		'
-	} >>.editmsg
+	} >>"$GIT_DIR"/.editmsg
 	;;
 esac
 
@@ -153,7 +153,7 @@ if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
 	echo "#	$GIT_DIR/MERGE_HEAD"
 	echo "# and try again"
 	echo "#"
-fi >>.editmsg
+fi >>"$GIT_DIR"/.editmsg
 
 PARENTS="-p HEAD"
 if GIT_DIR="$GIT_DIR" git-rev-parse --verify HEAD >/dev/null 2>&1
@@ -197,16 +197,16 @@ else
 	fi
 	PARENTS=""
 fi
-git-status >>.editmsg
+git-status >>"$GIT_DIR"/.editmsg
 if [ "$?" != "0" -a ! -f $GIT_DIR/MERGE_HEAD ]
 then
-	rm -f .editmsg
+	rm -f "$GIT_DIR"/.editmsg
 	git-status
 	exit 1
 fi
 case "$no_edit" in
 '')
-	${VISUAL:-${EDITOR:-vi}} .editmsg
+	${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/.editmsg
 	;;
 esac
 
@@ -214,16 +214,16 @@ case "$verify" in
 t)
 	if test -x "$GIT_DIR"/hooks/commit-msg
 	then
-		"$GIT_DIR"/hooks/commit-msg .editmsg || exit
+		"$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/.editmsg || exit
 	fi
 esac
 
-grep -v '^#' < .editmsg | git-stripspace > .cmitmsg
-grep -v -i '^Signed-off-by' .cmitmsg >.cmitchk
-if test -s .cmitchk
+grep -v '^#' < "$GIT_DIR"/.editmsg | git-stripspace > "$GIT_DIR"/.cmitmsg
+grep -v -i '^Signed-off-by' "$GIT_DIR"/.cmitmsg >"$GIT_DIR"/.cmitchk
+if test -s "$GIT_DIR"/.cmitchk
 then
 	tree=$(git-write-tree) &&
-	commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) &&
+	commit=$(cat "$GIT_DIR"/.cmitmsg | git-commit-tree $tree $PARENTS) &&
 	git-update-ref HEAD $commit $current &&
 	rm -f -- "$GIT_DIR/MERGE_HEAD"
 else
@@ -231,7 +231,7 @@ else
 	false
 fi
 ret="$?"
-rm -f .cmitmsg .editmsg .cmitchk
+rm -f "$GIT_DIR"/{.cmitmsg,.editmsg,.cmitchk}
 
 if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
 then
---
0.99.8.GIT
Junio C Hamano· Oct 5, 2005, 21:54 UTC · re: Santi Béjar · lore

Re: [PATCH] Write .editmsg in GIT_DIR to avoid being in git-status.

Santi Béjar <sbejar@gmail.com> writes:
> It appears in the git-status output during a git-commit if you have
> something in info/exclude.
... which does not worry me too much; you'll get used to it ;-).
> Also for .cmitmsg and .cmitchk to make git-commit work
> in read-only working trees.
If a working tree is read-only, I wonder what you are committing.

It might not be a bad idea to think about this a bit more before actually coding. You are moving things out of the working tree root level, which is a valid thing to do when worrying about a repository (or working tree) that you do not have write access to. We've had a fix similar to this for temporary files used by diff commands, which moved them to $TMPDIR or something like that. If the working tree root level is not writable for you, is it valid/reasonable to assume that $GIT_DIR is? Are there better places? E.g. perhaps $HOME/.gittmp/?

>  ret="$?"
> -rm -f .cmitmsg .editmsg .cmitchk
> +rm -f "$GIT_DIR"/{.cmitmsg,.editmsg,.cmitchk}

Please do not do "{a,b,c}". I think ksh can grok the rest of the git-commit.sh code, but not this.

Santi Bejar· Oct 6, 2005, 13:30 UTC · re: Junio C Hamano · lore

Re: [PATCH] Write .editmsg in GIT_DIR to avoid being in git-status.

2005/10/5, Junio C Hamano <junkio@cox.net>:
Show 7 quoted lines
> Santi B.ANijar <sbejar@gmail.com> writes:
>
> > It appears in the git-status output during a git-commit if you have
> > something in info/exclude.
>
> ... which does not worry me too much; you'll get used to it ;-).
>
I'm used too, but I don't think it's a 1.0 thing.
Show 5 quoted lines
> > Also for .cmitmsg and .cmitchk to make git-commit work
> > in read-only working trees.
>
> If a working tree is read-only, I wonder what you are committing.
>
I keep my /etc modifications in git, and I want to commit as a user not as root.
Show 9 quoted lines
> It might not be a bad idea to think about this a bit more before
> actually coding.  You are moving things out of the working tree
> root level, which is a valid thing to do when worrying about a
> repository (or working tree) that you do not have write access
> to.  We've had a fix similar to this for temporary files used by
> diff commands, which moved them to $TMPDIR or something like
> that.  If the working tree root level is not writable for you,
> is it valid/reasonable to assume that $GIT_DIR is?  Are there
> better places?  E.g. perhaps $HOME/.gittmp/?

Yes, it was just quick. I think the best way would be to write to /tmp but honor $TMPDIR.

Show 7 quoted lines
>
> >  ret="$?"
> > -rm -f .cmitmsg .editmsg .cmitchk
> > +rm -f "$GIT_DIR"/{.cmitmsg,.editmsg,.cmitchk}
>
> Please do not do "{a,b,c}".  I think ksh can grok the rest of
> the git-commit.sh code, but not this.
OK.
Junio C Hamano· Oct 6, 2005, 20:19 UTC · re: Santi Bejar · lore

Re: [PATCH] Write .editmsg in GIT_DIR to avoid being in git-status.

Santi Bejar <sbejar@gmail.com> writes:
>> If a working tree is read-only, I wonder what you are committing.
>
> I keep my /etc modifications in git, and I want to commit as a
> user not as root.

OK. Your /etc/.git is writable by you but /etc is not. Although I personally would do it a bit differently (my /etc sources would live in a different area which is a source tree and 'make install' as root would install the latest to /etc; no need for anything user writable under /etc, including /etc/.git/), I do not think your set-up is wrong -- we should support it.

>> ... If the working tree root level is not writable for you,
>> is it valid/reasonable to assume that $GIT_DIR is?

I changed my mind about this. $GIT_DIR by definition should be writable by you since we are talking about committing -- I think moving them to $GIT_DIR/ is a good change.

← back to recent threads