git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-am: fix detection of absolute paths for windows

From
Pat Thoyts <patthoyts@users.sourceforge.net>
Date
Sep 30, 2010, 13:24 UTC
Message-ID
<87tyl6hnu2.fsf_-_@fox.patthoyts.tk>
In-Reply-To
<201009282252.25688.j6t@kdbg.org>

Add an is_absolute_path function to abstract out platform differences in checking for an absolute or relative path. Specifically fixes t4150-am on Windows.

Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
---
In response to the following comment...
Show 6 quoted lines
>Johannes Sixt <j6t@kdbg.org> writes:
>>>       git-am: fix absolute path logic on Windows 
>>
>>This mistakes a file that has a colon in the second position as absolute, even 
>>on non-Windows. IIUC, this patch is not intended for upstream git.
>>

This patch is an alternative solution that only tries the Windows paths on msysGit. This is_absolute_path might find use elsewhere in the future so I elected to place it in the sh-setup script. Also added support for identifying a UNC path as absolute.

 git-am.sh       |   12 ++++++------
 git-sh-setup.sh |   15 +++++++++++++++
 2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/git-am.sh b/git-am.sh
index e7f008c..9317b38 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -444,12 +444,12 @@ else
 				set x
 				first=
 			}
-			case "$arg" in
-			/*)
-				set "$@" "$arg" ;;
-			*)
-				set "$@" "$prefix$arg" ;;
-			esac
+			if is_absolute_path "$arg"
+			then
+				set "$@" "$arg"
+			else
+				set "$@" "$prefix$arg"
+			fi
 		done
 		shift
 	fi
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 6131670..b9eb0bf 100644
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -209,5 +209,20 @@ case $(uname -s) in
 	find () {
 		/usr/bin/find "$@"
 	}
+	is_absolute_path () {
+		case "$1" in
+		/* | ?:* | \\\\*)
+			return 0 ;;
+		esac
+		return 1
+	}
 	;;
+*)
+	is_absolute_path () {
+		case "$1" in
+		/*)
+			return 0 ;;
+		esac
+		return 1
+	}
 esac
-- 
1.7.3
Previous: Eric SunshineNext: Johannes Sixt
Message 25 of 38 in “Pull request for msysGit patches”
  1. Pat ThoytsSep 28, 2010
  2. Junio C HamanoSep 28, 2010
  3. Johannes SixtSep 28, 2010
  4. Junio C HamanoSep 29, 2010
  5. Ævar Arnfjörð BjarmasonSep 28, 2010
  6. Pat ThoytsSep 30, 2010
  7. Ævar Arnfjörð BjarmasonSep 30, 2010
  8. Erik Faye-LundSep 30, 2010
  9. Eric SunshineSep 29, 2010
  10. msysGit patches for upstreamPat Thoyts, Sep 29, 2010
  11. Junio C HamanoSep 29, 2010
  12. 1/2 Make sure that git_getpass() never returns NULLPat Thoyts, Sep 29, 2010
  13. 2/2 Fix typo in pack-objects' usagePat Thoyts, Sep 29, 2010
  14. Johannes SixtSep 28, 2010
  15. Erik Faye-LundSep 28, 2010
  16. Johannes SixtSep 28, 2010
  17. Erik Faye-LundSep 28, 2010
  18. Erik Faye-LundSep 28, 2010
  19. Jonathan NiederSep 28, 2010
  20. Junio C HamanoSep 29, 2010
  21. Pat ThoytsSep 29, 2010
  22. Eric SunshineSep 29, 2010
  23. Junio C HamanoSep 29, 2010
  24. Eric SunshineSep 29, 2010
  25. git-am: fix detection of absolute paths for windowsPat Thoyts, Sep 30, 2010
  26. Johannes SixtOct 1, 2010
  27. git-am: fix detection of absolute paths for windowsPat Thoyts, Sep 30, 2010
  28. 0/4 make open/unlink failures user friendly on windows using retry/abortHeiko Voigt, Nov 7, 2010
  29. 1/4 mingw: move unlink wrapper to mingw.cHeiko Voigt, Nov 7, 2010
  30. 2/4 mingw: work around irregular failures of unlink on windowsHeiko Voigt, Nov 7, 2010
  31. 3/4 mingw: make failures to unlink or move raise a questionHeiko Voigt, Nov 7, 2010
  32. 4/4 mingw: add fallback for rmdir in case directory is in useHeiko Voigt, Nov 7, 2010
  33. Johannes SixtNov 7, 2010
  34. Heiko VoigtNov 7, 2010
  35. Johannes SixtNov 7, 2010
  36. yj2133011Sep 29, 2010
  37. Ramsay JonesSep 29, 2010
  38. Eric SunshineSep 29, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.